Mercurial > hg-stable
changeset 37693:31a0d47d69b3
lfs: update the HTTP status codes in error cases
I'm not bothering with validating PUT requests (for now), because the spec
doesn't explicitly call out a Content-Type (though the example transcript does
use the sensible 'application/octet-stream').
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 13 Apr 2018 16:32:33 -0400 |
parents | 10e5bb9678f4 |
children | d14dbf46e5c7 |
files | hgext/lfs/wireprotolfsserver.py mercurial/hgweb/common.py |
diffstat | 2 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/lfs/wireprotolfsserver.py Sun Feb 25 14:07:13 2018 -0500 +++ b/hgext/lfs/wireprotolfsserver.py Fri Apr 13 16:32:33 2018 -0400 @@ -26,6 +26,9 @@ HTTP_CREATED = hgwebcommon.HTTP_CREATED HTTP_BAD_REQUEST = hgwebcommon.HTTP_BAD_REQUEST HTTP_NOT_FOUND = hgwebcommon.HTTP_NOT_FOUND +HTTP_METHOD_NOT_ALLOWED = hgwebcommon.HTTP_METHOD_NOT_ALLOWED +HTTP_NOT_ACCEPTABLE = hgwebcommon.HTTP_NOT_ACCEPTABLE +HTTP_UNSUPPORTED_MEDIA_TYPE = hgwebcommon.HTTP_UNSUPPORTED_MEDIA_TYPE def handlewsgirequest(orig, rctx, req, res, checkperm): """Wrap wireprotoserver.handlewsgirequest() to possibly process an LFS @@ -105,12 +108,16 @@ # "operation": "upload" # } - if (req.method != b'POST' - or req.headers[b'Content-Type'] != b'application/vnd.git-lfs+json' - or req.headers[b'Accept'] != b'application/vnd.git-lfs+json'): - # TODO: figure out what the proper handling for a bad request to the - # Batch API is. - _sethttperror(res, HTTP_BAD_REQUEST, b'Invalid Batch API request') + if req.method != b'POST': + _sethttperror(res, HTTP_METHOD_NOT_ALLOWED) + return True + + if req.headers[b'Content-Type'] != b'application/vnd.git-lfs+json': + _sethttperror(res, HTTP_UNSUPPORTED_MEDIA_TYPE) + return True + + if req.headers[b'Accept'] != b'application/vnd.git-lfs+json': + _sethttperror(res, HTTP_NOT_ACCEPTABLE) return True # XXX: specify an encoding? @@ -315,6 +322,6 @@ return True else: - _sethttperror(res, HTTP_BAD_REQUEST, + _sethttperror(res, HTTP_METHOD_NOT_ALLOWED, message=b'Unsupported LFS transfer method: %s' % method) return True
--- a/mercurial/hgweb/common.py Sun Feb 25 14:07:13 2018 -0500 +++ b/mercurial/hgweb/common.py Fri Apr 13 16:32:33 2018 -0400 @@ -30,6 +30,8 @@ HTTP_FORBIDDEN = 403 HTTP_NOT_FOUND = 404 HTTP_METHOD_NOT_ALLOWED = 405 +HTTP_NOT_ACCEPTABLE = 406 +HTTP_UNSUPPORTED_MEDIA_TYPE = 415 HTTP_SERVER_ERROR = 500