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

3 messages from 2013-09-12 to 2013-09-12. Participants: brian m. carlson, Jonathan Nieder, Jeff King.
Thread: https://gitlist.dev/t/34912

## brian m. carlson, 2013-09-12 00:30

Subject: [PATCH v2] http-backend: provide Allow header for 405
Message-ID: <1378945801-122021-1-git-send-email-sandals@crustytoothpaste.net>
URL: https://gitlist.dev/e/1378945801-122021-1-git-send-email-sandals%40crustytoothpaste.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

```

## Jonathan Nieder, 2013-09-12 00:33

Subject: Re: [PATCH v2] http-backend: provide Allow header for 405
Message-ID: <20130912003343.GH4326@google.com>
URL: https://gitlist.dev/e/20130912003343.GH4326%40google.com
In-Reply-To: <1378945801-122021-1-git-send-email-sandals@crustytoothpaste.net>

```
brian m. carlson wrote:

> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>

Thanks again for noticing.

For what it's worth,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

```

## Jeff King, 2013-09-12 04:46

Subject: Re: [PATCH v2] http-backend: provide Allow header for 405
Message-ID: <20130912044637.GA1356@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20130912044637.GA1356%40sigill.intra.peff.net
In-Reply-To: <1378945801-122021-1-git-send-email-sandals@crustytoothpaste.net>

```
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 <sandals@crustytoothpaste.net>

Thanks, this looks good to me.

-Peff

```
