Skip to content

Commit 9247be0

Browse files
bk2204gitster
authored andcommitted
http-backend: provide Allow header for 405
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e45bda8 commit 9247be0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

http-backend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,11 @@ int main(int argc, char **argv)
564564

565565
if (strcmp(method, c->method)) {
566566
const char *proto = getenv("SERVER_PROTOCOL");
567-
if (proto && !strcmp(proto, "HTTP/1.1"))
567+
if (proto && !strcmp(proto, "HTTP/1.1")) {
568568
http_status(405, "Method Not Allowed");
569-
else
569+
hdr_str("Allow", !strcmp(c->method, "GET") ?
570+
"GET, HEAD" : c->method);
571+
} else
570572
http_status(400, "Bad Request");
571573
hdr_nocache();
572574
end_headers();

0 commit comments

Comments
 (0)