# HG changeset patch # User Matt Harbison # Date 1523651553 14400 # Node ID 31a0d47d69b3f4565e32ce0b851125d46c3f2d1c # Parent 10e5bb9678f4163f9977e5035536c024c61b7d53 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'). diff -r 10e5bb9678f4 -r 31a0d47d69b3 hgext/lfs/wireprotolfsserver.py --- 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 diff -r 10e5bb9678f4 -r 31a0d47d69b3 mercurial/hgweb/common.py --- 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