Show More
@@ -621,7 +621,10 b' def kwweb_skip(orig, web, req, tmpl):' | |||
|
621 | 621 | origmatch = kwt.match |
|
622 | 622 | kwt.match = util.never |
|
623 | 623 | try: |
|
624 |
|
|
|
624 | res = orig(web, req, tmpl) | |
|
625 | if res is web.res: | |
|
626 | res = res.sendresponse() | |
|
627 | for chunk in res: | |
|
625 | 628 | yield chunk |
|
626 | 629 | finally: |
|
627 | 630 | if kwt: |
@@ -91,9 +91,11 b' class requestcontext(object):' | |||
|
91 | 91 | is prone to race conditions. Instances of this class exist to hold |
|
92 | 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 | 95 | self.repo = repo |
|
96 | 96 | self.reponame = app.reponame |
|
97 | self.req = req | |
|
98 | self.res = res | |
|
97 | 99 | |
|
98 | 100 | self.archivespecs = archivespecs |
|
99 | 101 | |
@@ -305,7 +307,7 b' class hgweb(object):' | |||
|
305 | 307 | def _runwsgi(self, wsgireq, repo): |
|
306 | 308 | req = wsgireq.req |
|
307 | 309 | res = wsgireq.res |
|
308 | rctx = requestcontext(self, repo) | |
|
310 | rctx = requestcontext(self, repo, req, res) | |
|
309 | 311 | |
|
310 | 312 | # This state is global across all threads. |
|
311 | 313 | encoding.encoding = rctx.config('web', 'encoding') |
@@ -401,7 +403,15 b' class hgweb(object):' | |||
|
401 | 403 | rctx.ctype = ctype |
|
402 | 404 | content = webcommands.rawfile(rctx, wsgireq, tmpl) |
|
403 | 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 | 410 | content = getattr(webcommands, cmd)(rctx, wsgireq, tmpl) |
|
411 | ||
|
412 | if content is res: | |
|
413 | return res.sendresponse() | |
|
414 | ||
|
405 | 415 | wsgireq.respond(HTTP_OK, ctype) |
|
406 | 416 | |
|
407 | 417 | return content |
@@ -53,6 +53,16 b' class webcommand(object):' | |||
|
53 | 53 | The decorator takes as its positional arguments the name/path the |
|
54 | 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 | 66 | Usage: |
|
57 | 67 | |
|
58 | 68 | @webcommand('mycommand') |
@@ -1068,7 +1078,8 b' def filelog(web, req, tmpl):' | |||
|
1068 | 1078 | |
|
1069 | 1079 | latestentry = entries[:1] |
|
1070 | 1080 | |
|
1071 | return tmpl("filelog", | |
|
1081 | web.res.setbodygen(tmpl( | |
|
1082 | 'filelog', | |
|
1072 | 1083 |
|
|
1073 | 1084 |
|
|
1074 | 1085 |
|
@@ -1080,7 +1091,9 b' def filelog(web, req, tmpl):' | |||
|
1080 | 1091 |
|
|
1081 | 1092 |
|
|
1082 | 1093 |
|
|
1083 |
|
|
|
1094 | **pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))) | |
|
1095 | ||
|
1096 | return web.res | |
|
1084 | 1097 | |
|
1085 | 1098 | @webcommand('archive') |
|
1086 | 1099 | def archive(web, req, tmpl): |
General Comments 0
You need to be logged in to leave comments.
Login now