git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 12, 2013, 00:30 UTC
Message-ID
<1378945801-122021-1-git-send-email-sandals@crustytoothpaste.net>
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>
---
 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
Next: Jonathan Nieder
Message 1 of 3 in “http-backend: provide Allow header for 405”
  1. http-backend: provide Allow header for 405brian m. carlson, Sep 12, 2013
  2. Jonathan NiederSep 12, 2013
  3. Jeff KingSep 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.