62 about the HTTP response. |
58 about the HTTP response. |
63 |
59 |
64 The function can return the ``requestcontext.res`` instance to signal |
60 The function can return the ``requestcontext.res`` instance to signal |
65 that it wants to use this object to generate the response. If an iterable |
61 that it wants to use this object to generate the response. If an iterable |
66 is returned, the ``wsgirequest`` instance will be used and the returned |
62 is returned, the ``wsgirequest`` instance will be used and the returned |
67 content will constitute the response body. |
63 content will constitute the response body. ``True`` can be returned to |
|
64 indicate that the function already sent output and the caller doesn't |
|
65 need to do anything more to send the response. |
68 |
66 |
69 Usage: |
67 Usage: |
70 |
68 |
71 @webcommand('mycommand') |
69 @webcommand('mycommand') |
72 def mycommand(web, req, tmpl): |
70 def mycommand(web, req, tmpl): |
1208 if not files: |
1206 if not files: |
1209 raise ErrorResponse(HTTP_NOT_FOUND, |
1207 raise ErrorResponse(HTTP_NOT_FOUND, |
1210 'file(s) not found: %s' % file) |
1208 'file(s) not found: %s' % file) |
1211 |
1209 |
1212 mimetype, artype, extension, encoding = web.archivespecs[type_] |
1210 mimetype, artype, extension, encoding = web.archivespecs[type_] |
1213 headers = [ |
1211 |
1214 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
1212 web.res.headers['Content-Type'] = mimetype |
1215 ] |
1213 web.res.headers['Content-Disposition'] = 'attachment; filename=%s%s' % ( |
|
1214 name, extension) |
|
1215 |
1216 if encoding: |
1216 if encoding: |
1217 headers.append(('Content-Encoding', encoding)) |
1217 web.res.headers['Content-Encoding'] = encoding |
1218 req.headers.extend(headers) |
1218 |
1219 req.respond(HTTP_OK, mimetype) |
1219 web.res.setbodywillwrite() |
1220 |
1220 assert list(web.res.sendresponse()) == [] |
1221 bodyfh = requestmod.offsettrackingwriter(req.write) |
1221 |
|
1222 bodyfh = web.res.getbodyfile() |
1222 |
1223 |
1223 archival.archive(web.repo, bodyfh, cnode, artype, prefix=name, |
1224 archival.archive(web.repo, bodyfh, cnode, artype, prefix=name, |
1224 matchfn=match, |
1225 matchfn=match, |
1225 subrepos=web.configbool("web", "archivesubrepos")) |
1226 subrepos=web.configbool("web", "archivesubrepos")) |
1226 return [] |
1227 |
1227 |
1228 return True |
1228 |
1229 |
1229 @webcommand('static') |
1230 @webcommand('static') |
1230 def static(web, req, tmpl): |
1231 def static(web, req, tmpl): |
1231 fname = req.req.qsparams['file'] |
1232 fname = req.req.qsparams['file'] |
1232 # a repo owner may set web.static in .hg/hgrc to get any file |
1233 # a repo owner may set web.static in .hg/hgrc to get any file |