mirror of
https://github.com/golang/go
synced 2024-11-25 23:07:58 -07:00
http: avoid header duplication - take struct fields out of Header map
R=r CC=golang-dev, petar-m https://golang.org/cl/183132
This commit is contained in:
parent
690fcacdd3
commit
968d6a6d5a
@ -160,6 +160,11 @@ func (req *Request) Write(w io.Writer) os.Error {
|
|||||||
// Response.{GetHeader,AddHeader} and string constants for "Host",
|
// Response.{GetHeader,AddHeader} and string constants for "Host",
|
||||||
// "User-Agent" and "Referer".
|
// "User-Agent" and "Referer".
|
||||||
for k, v := range req.Header {
|
for k, v := range req.Header {
|
||||||
|
// Host, User-Agent, and Referer were sent from structure fields
|
||||||
|
// above; ignore them if they also appear in req.Header.
|
||||||
|
if k == "Host" || k == "User-Agent" || k == "Referer" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
io.WriteString(w, k+": "+v+"\r\n")
|
io.WriteString(w, k+": "+v+"\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,9 +502,12 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
|
|||||||
// GET http://www.google.com/index.html HTTP/1.1
|
// GET http://www.google.com/index.html HTTP/1.1
|
||||||
// Host: doesntmatter
|
// Host: doesntmatter
|
||||||
// the same. In the second case, any Host line is ignored.
|
// the same. In the second case, any Host line is ignored.
|
||||||
if v, present := req.Header["Host"]; present && req.URL.Host == "" {
|
if v, present := req.Header["Host"]; present {
|
||||||
|
if req.URL.Host == "" {
|
||||||
req.Host = v
|
req.Host = v
|
||||||
}
|
}
|
||||||
|
req.Header["Host"] = "", false
|
||||||
|
}
|
||||||
|
|
||||||
// RFC2616: Should treat
|
// RFC2616: Should treat
|
||||||
// Pragma: no-cache
|
// Pragma: no-cache
|
||||||
@ -525,9 +533,11 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
|
|||||||
// Pull out useful fields as a convenience to clients.
|
// Pull out useful fields as a convenience to clients.
|
||||||
if v, present := req.Header["Referer"]; present {
|
if v, present := req.Header["Referer"]; present {
|
||||||
req.Referer = v
|
req.Referer = v
|
||||||
|
req.Header["Referer"] = "", false
|
||||||
}
|
}
|
||||||
if v, present := req.Header["User-Agent"]; present {
|
if v, present := req.Header["User-Agent"]; present {
|
||||||
req.UserAgent = v
|
req.UserAgent = v
|
||||||
|
req.Header["User-Agent"] = "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Parse specific header values:
|
// TODO: Parse specific header values:
|
||||||
|
Loading…
Reference in New Issue
Block a user