Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webcommands.py @ 5993:948a41e77902
hgweb: explicit response status
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 01 Feb 2008 10:31:13 +0100 |
parents | 1cd1582ef25f |
children | fe8dbbe9520d |
comparison
equal
deleted
inserted
replaced
5992:30c40ba10963 | 5993:948a41e77902 |
---|---|
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import os, mimetypes | 8 import os, mimetypes |
9 from mercurial import revlog, util, hg | 9 from mercurial import revlog, util, hg |
10 from common import staticfile, ErrorResponse | 10 from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND |
11 | 11 |
12 # __all__ is populated with the allowed commands. Be sure to add to it if | 12 # __all__ is populated with the allowed commands. Be sure to add to it if |
13 # you're adding a new command, or the new command won't work. | 13 # you're adding a new command, or the new command won't work. |
14 | 14 |
15 __all__ = [ | 15 __all__ = [ |
25 return changelog(web, req, tmpl) | 25 return changelog(web, req, tmpl) |
26 | 26 |
27 def rawfile(web, req, tmpl): | 27 def rawfile(web, req, tmpl): |
28 path = web.cleanpath(req.form.get('file', [''])[0]) | 28 path = web.cleanpath(req.form.get('file', [''])[0]) |
29 if not path: | 29 if not path: |
30 return web.manifest(tmpl, web.changectx(req), path) | 30 content = web.manifest(tmpl, web.changectx(req), path) |
31 req.respond(HTTP_OK, web.ctype) | |
32 return content | |
31 | 33 |
32 try: | 34 try: |
33 fctx = web.filectx(req) | 35 fctx = web.filectx(req) |
34 except revlog.LookupError: | 36 except revlog.LookupError: |
35 return web.manifest(tmpl, web.changectx(req), path) | 37 content = web.manifest(tmpl, web.changectx(req), path) |
38 req.respond(HTTP_OK, web.ctype) | |
39 return content | |
36 | 40 |
37 path = fctx.path() | 41 path = fctx.path() |
38 text = fctx.data() | 42 text = fctx.data() |
39 mt = mimetypes.guess_type(path)[0] | 43 mt = mimetypes.guess_type(path)[0] |
40 if mt is None or util.binary(text): | 44 if mt is None or util.binary(text): |
41 mt = mt or 'application/octet-stream' | 45 mt = mt or 'application/octet-stream' |
42 | 46 |
43 req.httphdr(mt, path, len(text)) | 47 req.respond(HTTP_OK, mt, path, len(text)) |
44 return [text] | 48 return [text] |
45 | 49 |
46 def file(web, req, tmpl): | 50 def file(web, req, tmpl): |
47 path = web.cleanpath(req.form.get('file', [''])[0]) | 51 path = web.cleanpath(req.form.get('file', [''])[0]) |
48 if path: | 52 if path: |
102 allowed = web.configlist("web", "allow_archive") | 106 allowed = web.configlist("web", "allow_archive") |
103 if (type_ in web.archives and (type_ in allowed or | 107 if (type_ in web.archives and (type_ in allowed or |
104 web.configbool("web", "allow" + type_, False))): | 108 web.configbool("web", "allow" + type_, False))): |
105 web.archive(tmpl, req, req.form['node'][0], type_) | 109 web.archive(tmpl, req, req.form['node'][0], type_) |
106 return [] | 110 return [] |
107 | 111 raise ErrorResponse(HTTP_NOT_FOUND, 'Unsupported archive type: %s' % type_) |
108 raise ErrorResponse(400, 'Unsupported archive type: %s' % type_) | |
109 | 112 |
110 def static(web, req, tmpl): | 113 def static(web, req, tmpl): |
111 fname = req.form['file'][0] | 114 fname = req.form['file'][0] |
112 # a repo owner may set web.static in .hg/hgrc to get any file | 115 # a repo owner may set web.static in .hg/hgrc to get any file |
113 # readable by the user running the CGI script | 116 # readable by the user running the CGI script |