##// END OF EJS Templates
hgweb: support using new response object for web commands...
Gregory Szorc -
r36886:1f42d621 default
parent child Browse files
Show More
@@ -621,7 +621,10 b' def kwweb_skip(orig, web, req, tmpl):'
621 origmatch = kwt.match
621 origmatch = kwt.match
622 kwt.match = util.never
622 kwt.match = util.never
623 try:
623 try:
624 for chunk in orig(web, req, tmpl):
624 res = orig(web, req, tmpl)
625 if res is web.res:
626 res = res.sendresponse()
627 for chunk in res:
625 yield chunk
628 yield chunk
626 finally:
629 finally:
627 if kwt:
630 if kwt:
@@ -91,9 +91,11 b' class requestcontext(object):'
91 is prone to race conditions. Instances of this class exist to hold
91 is prone to race conditions. Instances of this class exist to hold
92 mutable and race-free state for requests.
92 mutable and race-free state for requests.
93 """
93 """
94 def __init__(self, app, repo):
94 def __init__(self, app, repo, req, res):
95 self.repo = repo
95 self.repo = repo
96 self.reponame = app.reponame
96 self.reponame = app.reponame
97 self.req = req
98 self.res = res
97
99
98 self.archivespecs = archivespecs
100 self.archivespecs = archivespecs
99
101
@@ -305,7 +307,7 b' class hgweb(object):'
305 def _runwsgi(self, wsgireq, repo):
307 def _runwsgi(self, wsgireq, repo):
306 req = wsgireq.req
308 req = wsgireq.req
307 res = wsgireq.res
309 res = wsgireq.res
308 rctx = requestcontext(self, repo)
310 rctx = requestcontext(self, repo, req, res)
309
311
310 # This state is global across all threads.
312 # This state is global across all threads.
311 encoding.encoding = rctx.config('web', 'encoding')
313 encoding.encoding = rctx.config('web', 'encoding')
@@ -401,7 +403,15 b' class hgweb(object):'
401 rctx.ctype = ctype
403 rctx.ctype = ctype
402 content = webcommands.rawfile(rctx, wsgireq, tmpl)
404 content = webcommands.rawfile(rctx, wsgireq, tmpl)
403 else:
405 else:
406 # Set some globals appropriate for web handlers. Commands can
407 # override easily enough.
408 res.status = '200 Script output follows'
409 res.headers['Content-Type'] = ctype
404 content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl)
410 content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl)
411
412 if content is res:
413 return res.sendresponse()
414
405 wsgireq.respond(HTTP_OK, ctype)
415 wsgireq.respond(HTTP_OK, ctype)
406
416
407 return content
417 return content
@@ -53,6 +53,16 b' class webcommand(object):'
53 The decorator takes as its positional arguments the name/path the
53 The decorator takes as its positional arguments the name/path the
54 command should be accessible under.
54 command should be accessible under.
55
55
56 When called, functions receive as arguments a ``requestcontext``,
57 ``wsgirequest``, and a templater instance for generatoring output.
58 The functions should populate the ``rctx.res`` object with details
59 about the HTTP response.
60
61 The function can return the ``requestcontext.res`` instance to signal
62 that it wants to use this object to generate the response. If an iterable
63 is returned, the ``wsgirequest`` instance will be used and the returned
64 content will constitute the response body.
65
56 Usage:
66 Usage:
57
67
58 @webcommand('mycommand')
68 @webcommand('mycommand')
@@ -1068,19 +1078,22 b' def filelog(web, req, tmpl):'
1068
1078
1069 latestentry = entries[:1]
1079 latestentry = entries[:1]
1070
1080
1071 return tmpl("filelog",
1081 web.res.setbodygen(tmpl(
1072 file=f,
1082 'filelog',
1073 nav=nav,
1083 file=f,
1074 symrev=webutil.symrevorshortnode(req, fctx),
1084 nav=nav,
1075 entries=entries,
1085 symrev=webutil.symrevorshortnode(req, fctx),
1076 descend=descend,
1086 entries=entries,
1077 patch=patch,
1087 descend=descend,
1078 latestentry=latestentry,
1088 patch=patch,
1079 linerange=linerange,
1089 latestentry=latestentry,
1080 revcount=revcount,
1090 linerange=linerange,
1081 morevars=morevars,
1091 revcount=revcount,
1082 lessvars=lessvars,
1092 morevars=morevars,
1083 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
1093 lessvars=lessvars,
1094 **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))))
1095
1096 return web.res
1084
1097
1085 @webcommand('archive')
1098 @webcommand('archive')
1086 def archive(web, req, tmpl):
1099 def archive(web, req, tmpl):
General Comments 0
You need to be logged in to leave comments. Login now