{"thread":{"id":"34880","subject":"[PATCH] http-backend: provide Allow header for 405","startedAt":"2013-09-08T18:15:06Z","lastAt":"2013-09-11T02:14:00Z","messageCount":4,"participants":["brian m. carlson","Jonathan Nieder","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"227145","messageId":"1378664106-95936-1-git-send-email-sandals@crustytoothpaste.net","threadId":"34880","inReplyTo":null,"subject":"[PATCH] http-backend: provide Allow header for 405","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2013-09-08T18:15:06Z","receivedAt":"2013-09-08T18:15:06Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"The HTTP 1.1 standard requires an Allow header for 405 Method Not Allowed:\n\n  The response MUST include an Allow header containing a list of valid methods\n  for the requested resource.\n\nSo provide such a header when we return a 405 to the user agent.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n http-backend.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/http-backend.c b/http-backend.c\nindex 0324417..8c61084 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -594,8 +594,11 @@ int main(int argc, char **argv)\n \n \t\t\tif (strcmp(method, c->method)) {\n \t\t\t\tconst char *proto = getenv(\"SERVER_PROTOCOL\");\n-\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\"))\n+\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\")) {\n \t\t\t\t\thttp_status(405, \"Method Not Allowed\");\n+\t\t\t\t\thdr_str(\"Allow\", !strcmp(\"GET\", c->method) ?\n+\t\t\t\t\t\t\"GET, HEAD\" : c->method);\n+\t\t\t\t}\n \t\t\t\telse\n \t\t\t\t\thttp_status(400, \"Bad Request\");\n \t\t\t\thdr_nocache();\n-- \n1.8.4.rc3\n"},{"id":"227194","messageId":"20130909041812.GA3430@elie.Belkin","threadId":"34880","inReplyTo":"1378664106-95936-1-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH] http-backend: provide Allow header for 405","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-09-09T04:18:12Z","receivedAt":"2013-09-09T04:18:12Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nbrian m. carlson wrote:\n\n> --- a/http-backend.c\n> +++ b/http-backend.c\n> @@ -594,8 +594,11 @@ int main(int argc, char **argv)\n>  \n>  \t\t\tif (strcmp(method, c->method)) {\n>  \t\t\t\tconst char *proto = getenv(\"SERVER_PROTOCOL\");\n> -\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\"))\n> +\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\")) {\n>  \t\t\t\t\thttp_status(405, \"Method Not Allowed\");\n> +\t\t\t\t\thdr_str(\"Allow\", !strcmp(\"GET\", c->method) ?\n> +\t\t\t\t\t\t\"GET, HEAD\" : c->method);\n> +\t\t\t\t}\n>  \t\t\t\telse\n\nSmall style nit: the closing brace should go on the same line as the\n\"else\", like so:\n\n\t\t\t\tif (proto && ...) {\n\t\t\t\t\t...\n\t\t\t\t} else\n\t\t\t\t\thttp_status(400, \"Bad Request\");\n\nAnother micronit: the comparison should be !strcmp(c->method, \"GET\")\n--- variable first, then constant it is being compared to.\n\nThe functional change looks good.\n\nThanks,\nJonathan\n"},{"id":"227303","messageId":"20130910062359.GA19638@sigill.intra.peff.net","threadId":"34880","inReplyTo":"1378664106-95936-1-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH] http-backend: provide Allow header for 405","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-09-10T06:24:00Z","receivedAt":"2013-09-10T06:24:00Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Sep 08, 2013 at 06:15:06PM +0000, brian m. carlson wrote:\n\n> The HTTP 1.1 standard requires an Allow header for 405 Method Not Allowed:\n> \n>   The response MUST include an Allow header containing a list of valid methods\n>   for the requested resource.\n> \n> So provide such a header when we return a 405 to the user agent.\n\nMakes sense.\n\n>  \t\t\tif (strcmp(method, c->method)) {\n>  \t\t\t\tconst char *proto = getenv(\"SERVER_PROTOCOL\");\n> -\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\"))\n> +\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\")) {\n>  \t\t\t\t\thttp_status(405, \"Method Not Allowed\");\n> +\t\t\t\t\thdr_str(\"Allow\", !strcmp(\"GET\", c->method) ?\n> +\t\t\t\t\t\t\"GET, HEAD\" : c->method);\n> +\t\t\t\t}\n\nIt took me a minute to figure out what is going on here. But we seem to\nconvert HEAD requests into GETs elsewhere, so any \"GET\" service should\nbe able to do either.\n\nLooks OK to me.\n\n-Peff\n"},{"id":"227402","messageId":"20130911021359.GA118418@vauxhall.crustytoothpaste.net","threadId":"34880","inReplyTo":"20130909041812.GA3430@elie.Belkin","subject":"Re: [PATCH] http-backend: provide Allow header for 405","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2013-09-11T02:14:00Z","receivedAt":"2013-09-11T02:14:00Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Sep 08, 2013 at 09:18:12PM -0700, Jonathan Nieder wrote:\n> > --- a/http-backend.c\n> > +++ b/http-backend.c\n> > @@ -594,8 +594,11 @@ int main(int argc, char **argv)\n> >  \n> >  \t\t\tif (strcmp(method, c->method)) {\n> >  \t\t\t\tconst char *proto = getenv(\"SERVER_PROTOCOL\");\n> > -\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\"))\n> > +\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\")) {\n> >  \t\t\t\t\thttp_status(405, \"Method Not Allowed\");\n> > +\t\t\t\t\thdr_str(\"Allow\", !strcmp(\"GET\", c->method) ?\n> > +\t\t\t\t\t\t\"GET, HEAD\" : c->method);\n> > +\t\t\t\t}\n> >  \t\t\t\telse\n> \n> Small style nit: the closing brace should go on the same line as the\n> \"else\", like so:\n> \n> \t\t\t\tif (proto && ...) {\n> \t\t\t\t\t...\n> \t\t\t\t} else\n> \t\t\t\t\thttp_status(400, \"Bad Request\");\n> \n> Another micronit: the comparison should be !strcmp(c->method, \"GET\")\n> --- variable first, then constant it is being compared to.\n> \n> The functional change looks good.\n\nI plan on doing a reroll tomorrow.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}