src/pkg/http/client.go | 2 +- src/pkg/http/readrequest_test.go | 2 +- src/pkg/http/request.go | 2 +- src/pkg/http/requestwrite_test.go | 4 ++-- src/pkg/http/response.go | 17 ++++++++--------- src/pkg/http/responsewrite_test.go | 6 +++--- diff --git a/src/pkg/http/client.go b/src/pkg/http/client.go index 82fff780016d79c8fe87eaa04b7b3b9fd0298e40..c24eea58191832ad09d89f98992ddfe0ab42ea0c 100644 --- a/src/pkg/http/client.go +++ b/src/pkg/http/client.go @@ -117,7 +117,7 @@ // Most the callers of send (Get, Post, et al) don't need // Headers, leaving it uninitialized. We guarantee to the // Transport that this has been initialized, though. if req.Header == nil { - req.Header = Header(make(map[string][]string)) + req.Header = make(Header) } info := req.URL.RawUserinfo diff --git a/src/pkg/http/readrequest_test.go b/src/pkg/http/readrequest_test.go index 6ee07bc9148a2687894d036ff7423ce96123de5f..19e2ff77476a97581c0f7f151b0af4cef8a750d8 100644 --- a/src/pkg/http/readrequest_test.go +++ b/src/pkg/http/readrequest_test.go @@ -93,7 +93,7 @@ }, Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1, - Header: map[string][]string{}, + Header: Header{}, Close: false, ContentLength: -1, Host: "test", diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go index 2f6e33ae9b0d7dc7f8b133af44fb45d8cc4db946..d8456bab3217353fb2935a861a6ff1100ef3d926 100644 --- a/src/pkg/http/request.go +++ b/src/pkg/http/request.go @@ -247,7 +247,7 @@ // One solution would be to remove the Host, UserAgent, and Referer fields // from Request, and introduce Request methods along the lines of // Response.{GetHeader,AddHeader} and string constants for "Host", // "User-Agent" and "Referer". - err = writeSortedKeyValue(w, req.Header, reqExcludeHeader) + err = writeSortedHeader(w, req.Header, reqExcludeHeader) if err != nil { return err } diff --git a/src/pkg/http/requestwrite_test.go b/src/pkg/http/requestwrite_test.go index a0cc46066630ac06ed0d3aef0ea0f51f0da67b37..03a766efd8cc276407418c72d61e3a140a31b90d 100644 --- a/src/pkg/http/requestwrite_test.go +++ b/src/pkg/http/requestwrite_test.go @@ -84,7 +84,7 @@ Path: "/search", }, ProtoMajor: 1, ProtoMinor: 1, - Header: map[string][]string{}, + Header: Header{}, TransferEncoding: []string{"chunked"}, }, @@ -112,7 +112,7 @@ Path: "/search", }, ProtoMajor: 1, ProtoMinor: 1, - Header: map[string][]string{}, + Header: Header{}, Close: true, TransferEncoding: []string{"chunked"}, }, diff --git a/src/pkg/http/response.go b/src/pkg/http/response.go index 4fd00ad61ea873c1434c7d3157ef2835d2cedffa..3d77c55551081b7495a579187ed428baefe2247c 100644 --- a/src/pkg/http/response.go +++ b/src/pkg/http/response.go @@ -67,10 +67,9 @@ // closed after reading Body. The value is advice for clients: neither // ReadResponse nor Response.Write ever closes a connection. Close bool - // Trailer maps trailer keys to values. Like for Header, if the - // response has multiple trailer lines with the same key, they will be - // concatenated, delimited by commas. - Trailer map[string][]string + // Trailer maps trailer keys to values, in the same + // format as the header. + Trailer Header } // ReadResponse reads and returns an HTTP response from r. The RequestMethod @@ -193,7 +192,7 @@ return err } // Rest of header - err = writeSortedKeyValue(w, resp.Header, respExcludeHeader) + err = writeSortedHeader(w, resp.Header, respExcludeHeader) if err != nil { return err } @@ -215,16 +214,16 @@ // Success return nil } -func writeSortedKeyValue(w io.Writer, kvm map[string][]string, exclude map[string]bool) os.Error { - keys := make([]string, 0, len(kvm)) - for k := range kvm { +func writeSortedHeader(w io.Writer, h Header, exclude map[string]bool) os.Error { + keys := make([]string, 0, len(h)) + for k := range h { if !exclude[k] { keys = append(keys, k) } } sort.SortStrings(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 { return err } diff --git a/src/pkg/http/responsewrite_test.go b/src/pkg/http/responsewrite_test.go index aabb833f9c867123dca2cab03195a04b1b16cd06..228ed5f7d1ed6bc94addceb61f1add6ce8f8b412 100644 --- a/src/pkg/http/responsewrite_test.go +++ b/src/pkg/http/responsewrite_test.go @@ -22,7 +22,7 @@ StatusCode: 503, ProtoMajor: 1, ProtoMinor: 0, RequestMethod: "GET", - Header: map[string][]string{}, + Header: Header{}, Body: nopCloser{bytes.NewBufferString("abcdef")}, ContentLength: 6, }, @@ -38,7 +38,7 @@ StatusCode: 200, ProtoMajor: 1, ProtoMinor: 0, RequestMethod: "GET", - Header: map[string][]string{}, + Header: Header{}, Body: nopCloser{bytes.NewBufferString("abcdef")}, ContentLength: -1, }, @@ -53,7 +53,7 @@ StatusCode: 200, ProtoMajor: 1, ProtoMinor: 1, RequestMethod: "GET", - Header: map[string][]string{}, + Header: Header{}, Body: nopCloser{bytes.NewBufferString("abcdef")}, ContentLength: 6, TransferEncoding: []string{"chunked"},