[PATCH v2] http-backend: provide Allow header for 405

Subsystems: the rest

DORMANTno replies

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH v2] http-backend: provide Allow header for 405

From: brian m. carlson <hidden>
Date: 2016-06-15 22:58:44

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 <redacted>
---
 http-backend.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/http-backend.c b/http-backend.c
index 0324417..8c464bd 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -594,9 +594,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();
-- 
1.8.4.rc3

Re: [PATCH v2] http-backend: provide Allow header for 405

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:58:44

brian m. carlson wrote:
Signed-off-by: brian m. carlson <redacted>
Thanks again for noticing.

For what it's worth,
Reviewed-by: Jonathan Nieder <redacted>

Re: [PATCH v2] http-backend: provide Allow header for 405

From: Jeff King <hidden>
Date: 2016-06-15 22:58:44

On Thu, Sep 12, 2013 at 12:30:01AM +0000, brian m. carlson wrote:
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 <redacted>
Thanks, this looks good to me.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help