Mercurial > public > mercurial-scm > hg
diff mercurial/hgweb/common.py @ 5993:948a41e77902
hgweb: explicit response status
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 01 Feb 2008 10:31:13 +0100 |
parents | c301f15c965a |
children | f7f25f58693a |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Fri Feb 01 10:31:09 2008 +0100 +++ b/mercurial/hgweb/common.py Fri Feb 01 10:31:13 2008 +0100 @@ -8,6 +8,11 @@ import errno, mimetypes, os +HTTP_OK = 200 +HTTP_BAD_REQUEST = 400 +HTTP_NOT_FOUND = 404 +HTTP_SERVER_ERROR = 500 + class ErrorResponse(Exception): def __init__(self, code, message=None): Exception.__init__(self) @@ -54,18 +59,15 @@ try: os.stat(path) ct = mimetypes.guess_type(path)[0] or "text/plain" - req.header([ - ('Content-Type', ct), - ('Content-Length', str(os.path.getsize(path))) - ]) + req.respond(HTTP_OK, ct, length = os.path.getsize(path)) return file(path, 'rb').read() except TypeError: - raise ErrorResponse(500, 'illegal file name') + raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal file name') except OSError, err: if err.errno == errno.ENOENT: - raise ErrorResponse(404) + raise ErrorResponse(HTTP_NOT_FOUND) else: - raise ErrorResponse(500, err.strerror) + raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) def style_map(templatepath, style): """Return path to mapfile for a given style.