Commit 0db312b6 authored by Russ Cox's avatar Russ Cox

http: use Header type consistently

R=bradfitzgo, dsymonds
CC=golang-dev
https://golang.org/cl/4244053
parent 7fb65a93
...@@ -117,7 +117,7 @@ func send(req *Request, t Transport) (resp *Response, err os.Error) { ...@@ -117,7 +117,7 @@ func send(req *Request, t Transport) (resp *Response, err os.Error) {
// Headers, leaving it uninitialized. We guarantee to the // Headers, leaving it uninitialized. We guarantee to the
// Transport that this has been initialized, though. // Transport that this has been initialized, though.
if req.Header == nil { if req.Header == nil {
req.Header = Header(make(map[string][]string)) req.Header = make(Header)
} }
info := req.URL.RawUserinfo info := req.URL.RawUserinfo
......
...@@ -93,7 +93,7 @@ var reqTests = []reqTest{ ...@@ -93,7 +93,7 @@ var reqTests = []reqTest{
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
Header: map[string][]string{}, Header: Header{},
Close: false, Close: false,
ContentLength: -1, ContentLength: -1,
Host: "test", Host: "test",
......
...@@ -247,7 +247,7 @@ func (req *Request) write(w io.Writer, usingProxy bool) os.Error { ...@@ -247,7 +247,7 @@ func (req *Request) write(w io.Writer, usingProxy bool) os.Error {
// from Request, and introduce Request methods along the lines of // from Request, and introduce Request methods along the lines of
// Response.{GetHeader,AddHeader} and string constants for "Host", // Response.{GetHeader,AddHeader} and string constants for "Host",
// "User-Agent" and "Referer". // "User-Agent" and "Referer".
err = writeSortedKeyValue(w, req.Header, reqExcludeHeader) err = writeSortedHeader(w, req.Header, reqExcludeHeader)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -84,7 +84,7 @@ var reqWriteTests = []reqWriteTest{ ...@@ -84,7 +84,7 @@ var reqWriteTests = []reqWriteTest{
}, },
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
Header: map[string][]string{}, Header: Header{},
TransferEncoding: []string{"chunked"}, TransferEncoding: []string{"chunked"},
}, },
...@@ -112,7 +112,7 @@ var reqWriteTests = []reqWriteTest{ ...@@ -112,7 +112,7 @@ var reqWriteTests = []reqWriteTest{
}, },
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
Header: map[string][]string{}, Header: Header{},
Close: true, Close: true,
TransferEncoding: []string{"chunked"}, TransferEncoding: []string{"chunked"},
}, },
......
...@@ -67,10 +67,9 @@ type Response struct { ...@@ -67,10 +67,9 @@ type Response struct {
// ReadResponse nor Response.Write ever closes a connection. // ReadResponse nor Response.Write ever closes a connection.
Close bool Close bool
// Trailer maps trailer keys to values. Like for Header, if the // Trailer maps trailer keys to values, in the same
// response has multiple trailer lines with the same key, they will be // format as the header.
// concatenated, delimited by commas. Trailer Header
Trailer map[string][]string
} }
// ReadResponse reads and returns an HTTP response from r. The RequestMethod // ReadResponse reads and returns an HTTP response from r. The RequestMethod
...@@ -193,7 +192,7 @@ func (resp *Response) Write(w io.Writer) os.Error { ...@@ -193,7 +192,7 @@ func (resp *Response) Write(w io.Writer) os.Error {
} }
// Rest of header // Rest of header
err = writeSortedKeyValue(w, resp.Header, respExcludeHeader) err = writeSortedHeader(w, resp.Header, respExcludeHeader)
if err != nil { if err != nil {
return err return err
} }
...@@ -215,16 +214,16 @@ func (resp *Response) Write(w io.Writer) os.Error { ...@@ -215,16 +214,16 @@ func (resp *Response) Write(w io.Writer) os.Error {
return nil return nil
} }
func writeSortedKeyValue(w io.Writer, kvm map[string][]string, exclude map[string]bool) os.Error { func writeSortedHeader(w io.Writer, h Header, exclude map[string]bool) os.Error {
keys := make([]string, 0, len(kvm)) keys := make([]string, 0, len(h))
for k := range kvm { for k := range h {
if !exclude[k] { if !exclude[k] {
keys = append(keys, k) keys = append(keys, k)
} }
} }
sort.SortStrings(keys) sort.SortStrings(keys)
for _, k := range keys { for _, k := range keys {
for _, v := range kvm[k] { for _, v := range h[k] {
if _, err := fmt.Fprintf(w, "%s: %s\r\n", k, v); err != nil { if _, err := fmt.Fprintf(w, "%s: %s\r\n", k, v); err != nil {
return err return err
} }
......
...@@ -22,7 +22,7 @@ var respWriteTests = []respWriteTest{ ...@@ -22,7 +22,7 @@ var respWriteTests = []respWriteTest{
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 0, ProtoMinor: 0,
RequestMethod: "GET", RequestMethod: "GET",
Header: map[string][]string{}, Header: Header{},
Body: nopCloser{bytes.NewBufferString("abcdef")}, Body: nopCloser{bytes.NewBufferString("abcdef")},
ContentLength: 6, ContentLength: 6,
}, },
...@@ -38,7 +38,7 @@ var respWriteTests = []respWriteTest{ ...@@ -38,7 +38,7 @@ var respWriteTests = []respWriteTest{
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 0, ProtoMinor: 0,
RequestMethod: "GET", RequestMethod: "GET",
Header: map[string][]string{}, Header: Header{},
Body: nopCloser{bytes.NewBufferString("abcdef")}, Body: nopCloser{bytes.NewBufferString("abcdef")},
ContentLength: -1, ContentLength: -1,
}, },
...@@ -53,7 +53,7 @@ var respWriteTests = []respWriteTest{ ...@@ -53,7 +53,7 @@ var respWriteTests = []respWriteTest{
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
RequestMethod: "GET", RequestMethod: "GET",
Header: map[string][]string{}, Header: Header{},
Body: nopCloser{bytes.NewBufferString("abcdef")}, Body: nopCloser{bytes.NewBufferString("abcdef")},
ContentLength: 6, ContentLength: 6,
TransferEncoding: []string{"chunked"}, TransferEncoding: []string{"chunked"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment