Skip to content

Commit

Permalink
http-backend: provide Allow header for 405
Browse files Browse the repository at this point in the history
The HTTP 1.1 standard requires an Allow header for 405 Method Not Allowed:

  The response MUST include an Allow header containing a list of valid methods
  for the requested resource.

So provide such a header when we return a 405 to the user agent.

Signed-off-by: Brian M. Carlson <sandals@crustytoothpaste.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brian M. Carlson authored and Junio C Hamano committed Sep 12, 2013
1 parent e45bda8 commit 9247be0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions http-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,11 @@ int main(int argc, char **argv)

if (strcmp(method, c->method)) {
const char *proto = getenv("SERVER_PROTOCOL");
if (proto && !strcmp(proto, "HTTP/1.1"))
if (proto && !strcmp(proto, "HTTP/1.1")) {
http_status(405, "Method Not Allowed");
else
hdr_str("Allow", !strcmp(c->method, "GET") ?
"GET, HEAD" : c->method);
} else
http_status(400, "Bad Request");
hdr_nocache();
end_headers();
Expand Down

0 comments on commit 9247be0

Please sign in to comment.