Skip to content

net/http: setting Content-Type header to []string{""} in http handler causes two Content-Type headers to be emitted #5953

@josharian

Description

@josharian
What steps will reproduce the problem?

Start up this server locally:

http://play.golang.org/p/GSGc0TFU0A

then:

curl -v localhost:6000


What is the expected output?

Only one Content-Type header in the raw response. (See below.)


What do you see instead?

After trimming a bit of noise:

$ curl -v localhost:6000
> GET / HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x
zlib/1.2.5
> Host: localhost:6000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: 
< Content-Type: text/plain; charset=utf-8
< Content-Length: 0
< Date: Thu, 25 Jul 2013 01:08:53 GMT


Which compiler are you using (5g, 6g, 8g, gccgo)?

6g


Which operating system are you using?

OS X


Which version are you using?  (run 'go version')

1.1.1


Please provide any additional information below.

The problematic line is:

  header["Content-Type"] = []string{""}

Any non-empty string here will not trigger the double headers. See
https://golang.org/issue/5950 for context about why I encountered
this.

A similar issue does not occur for the Date header, the Content-Length header, nor any
other header that I tried.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions