From 8f45bf7b9e605547c26a467d543a1af9cc450bdf Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 19 Jan 2015 21:24:18 +0900 Subject: [PATCH] integration: Use []hpack.HeaderField instead of http.Header in requestParam With array, we can control the order of header field directly. --- integration-tests/nghttpx_test.go | 17 +++++++++-------- integration-tests/server_tester.go | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/integration-tests/nghttpx_test.go b/integration-tests/nghttpx_test.go index ddeee27c..aecfd7d1 100644 --- a/integration-tests/nghttpx_test.go +++ b/integration-tests/nghttpx_test.go @@ -3,6 +3,7 @@ package nghttp2 import ( "fmt" "github.com/bradfitz/http2" + "github.com/bradfitz/http2/hpack" "net/http" "testing" ) @@ -54,8 +55,8 @@ func TestAddXff2(t *testing.T) { _, err := st.http2(requestParam{ name: "TestAddXff2", - header: http.Header{ - "x-forwarded-for": []string{"host"}, + header: []hpack.HeaderField{ + pair("x-forwarded-for", "host"), }, }) if err != nil { @@ -73,8 +74,8 @@ func TestStripXff(t *testing.T) { _, err := st.http2(requestParam{ name: "TestStripXff1", - header: http.Header{ - "x-forwarded-for": []string{"host"}, + header: []hpack.HeaderField{ + pair("x-forwarded-for", "host"), }, }) if err != nil { @@ -98,8 +99,8 @@ func TestStripAddXff(t *testing.T) { _, err := st.http2(requestParam{ name: "TestStripAddXff", - header: http.Header{ - "x-forwarded-for": []string{"host"}, + header: []hpack.HeaderField{ + pair("x-forwarded-for", "host"), }, }) if err != nil { @@ -116,8 +117,8 @@ func TestHTTP2BadRequestCL(t *testing.T) { res, err := st.http2(requestParam{ name: "TestHTTP2BadRequestCL", method: "POST", - header: http.Header{ - "content-length": []string{"1024"}, + header: []hpack.HeaderField{ + pair("content-length", "1024"), }, body: []byte("foo"), }) diff --git a/integration-tests/server_tester.go b/integration-tests/server_tester.go index 0b14519f..8545c8d4 100644 --- a/integration-tests/server_tester.go +++ b/integration-tests/server_tester.go @@ -134,15 +134,14 @@ func (st *serverTester) readFrame() (http2.Frame, error) { } type requestParam struct { - name string // name for this request to identify the request - // in log easily - streamID uint32 // stream ID, automatically assigned if 0 - method string // method, defaults to GET - scheme string // scheme, defaults to http - authority string // authority, defaults to backend server address - path string // path, defaults to / - header http.Header // additional request header fields - body []byte // request body + name string // name for this request to identify the request in log easily + streamID uint32 // stream ID, automatically assigned if 0 + method string // method, defaults to GET + scheme string // scheme, defaults to http + authority string // authority, defaults to backend server address + path string // path, defaults to / + header []hpack.HeaderField // additional request header fields + body []byte // request body } func (st *serverTester) http2(rp requestParam) (*serverResponse, error) { @@ -195,10 +194,8 @@ func (st *serverTester) http2(rp requestParam) (*serverResponse, error) { _ = st.enc.WriteField(pair("test-case", rp.name)) - for k, v := range rp.header { - for _, h := range v { - _ = st.enc.WriteField(pair(strings.ToLower(k), h)) - } + for _, h := range rp.header { + _ = st.enc.WriteField(pair(strings.ToLower(h.Name), h.Value)) } err := st.fr.WriteHeaders(http2.HeadersFrameParam{