When handling inbound requests, I'm noticing that requests with multiple values for a single header are being treated as single value in the http.Request's Header property.
Current behaviour for the following function.
func foo(responseWriter http.ResponseWriter, request *http.Request) {
Log.Debug("Accept header: %v. Length: %v", request.Header["Accept"])
fmt.Fprintf(responseWriter, "\n")
}
Request with two "Accept" header lines:
$ curl -H "Accept:application/json" -H "Accept:text/plain" localhost:8080/foo -vvv
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /foo HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept:application/json
> Accept:text/plain
>
Output is a slice with two entries:
Accept header: [application/json text/plain]. Length: 2
Request with a single "Accept" header line containing multiple comma-separated values. I would hope that its behaviour would be identical to above, but instead it is treated as one value:
$ curl -H "Accept: application/json, text/plain" localhost:8080/foo -vvv
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /foo HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: application/json, text/plain
>
Output:
Accept header: [application/json, text/plain]. Length: 1
Having to handle these two functionally identical requests differently depending on how a client formats its requests is ugly in my opinion . Am I doing something wrong?