integration: Use []hpack.HeaderField instead of http.Header in requestParam

With array, we can control the order of header field directly.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-19 21:24:18 +09:00
parent 09939cf6bc
commit 8f45bf7b9e
2 changed files with 19 additions and 21 deletions

View File

@ -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"),
})

View File

@ -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{