Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http server doesn't support writing multiple headers with the same name #488

Closed
hoisie opened this issue Jan 2, 2010 · 4 comments
Closed

Comments

@hoisie
Copy link
Contributor

hoisie commented Jan 2, 2010

conn.SetHeader(name,val) by default overrides any previous value under the
same name. 

This makes it very difficult to write multiple Set-Cookie headers, for
instance. 

Headers with the same name are quite common for http servers. Just query
google.com and you'll see an example (the two Set-Cookie headers). 


mhoisie@Kenna gotest $ telnet google.com 80
Trying 74.125.19.106...
Connected to google.com.
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 200 OK
Date: Sat, 02 Jan 2010 17:21:48 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie:
PREF=ID=c87cc887bc1adb8c:TM=1262452908:LM=1262452908:S=UkIVKQcywQeWefwp;
expires=Mon, 02-Jan-2012 17:21:48 GMT; path=/; domain=.google.com
Set-Cookie:
NID=30=ulQicanZo3Kkybu2XhzSJSPxzgqWseouLX8fCcqxnFy6n7A90LE_nFx0PE2ihD5Z9_bCMZZqy8XG-bP_OenKaMtS9AqQY6_0bn_5Oc2LCtbj7Oik9cLqaTre-Hwprlpc;
expires=Sun, 04-Jul-2010 17:21:48 GMT; path=/; domain=.google.com; HttpOnly
Server: gws
X-XSS-Protection: 0
Transfer-Encoding: chunked
@rsc
Copy link
Contributor

rsc commented Jan 3, 2010

Comment 1:

There should be a way to get at the current header value.
Set means set, i.e. overwrite.  But if you could get at the current
header value you could set the new value to the old one + ", " + 
the one you want to add.
RFC 2616 says that sending multiple headers must be
semantically equivalent to one header with the multiple
values separated by commas.

Owner changed to r...@golang.org.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

bradfitz commented Mar 4, 2011

Comment 2:

We could replace ResponseWriter's SetHeader(k,v) with a Header() http.Header so client
code ends up looking like:
func handler(rw http.ResponseWriter, ...) {
     rw.Header().Set("Content-Length", "13")
     rw.Header().Add("X-Foo", "foo")
     rw.Header().Add("X-Foo", "foo")
}
If we do this, though, I'd like to change other stuff in ResponseWriter at the same
time.  Comments in https://golang.org/issue/1317?c=2

@bradfitz
Copy link
Contributor

bradfitz commented Mar 9, 2011

Comment 3:

Patch:
http://golang.org/cl/4239076/

Owner changed to bradf...@golang.org.

@bradfitz
Copy link
Contributor

bradfitz commented Mar 9, 2011

Comment 4:

This issue was closed by revision 2c420ec.

Status changed to Fixed.

@hoisie hoisie added the fixed label Mar 9, 2011
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants