Commit 8f45bf7b authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

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

With array, we can control the order of header field directly.
parent 09939cf6
...@@ -3,6 +3,7 @@ package nghttp2 ...@@ -3,6 +3,7 @@ package nghttp2
import ( import (
"fmt" "fmt"
"github.com/bradfitz/http2" "github.com/bradfitz/http2"
"github.com/bradfitz/http2/hpack"
"net/http" "net/http"
"testing" "testing"
) )
...@@ -54,8 +55,8 @@ func TestAddXff2(t *testing.T) { ...@@ -54,8 +55,8 @@ func TestAddXff2(t *testing.T) {
_, err := st.http2(requestParam{ _, err := st.http2(requestParam{
name: "TestAddXff2", name: "TestAddXff2",
header: http.Header{ header: []hpack.HeaderField{
"x-forwarded-for": []string{"host"}, pair("x-forwarded-for", "host"),
}, },
}) })
if err != nil { if err != nil {
...@@ -73,8 +74,8 @@ func TestStripXff(t *testing.T) { ...@@ -73,8 +74,8 @@ func TestStripXff(t *testing.T) {
_, err := st.http2(requestParam{ _, err := st.http2(requestParam{
name: "TestStripXff1", name: "TestStripXff1",
header: http.Header{ header: []hpack.HeaderField{
"x-forwarded-for": []string{"host"}, pair("x-forwarded-for", "host"),
}, },
}) })
if err != nil { if err != nil {
...@@ -98,8 +99,8 @@ func TestStripAddXff(t *testing.T) { ...@@ -98,8 +99,8 @@ func TestStripAddXff(t *testing.T) {
_, err := st.http2(requestParam{ _, err := st.http2(requestParam{
name: "TestStripAddXff", name: "TestStripAddXff",
header: http.Header{ header: []hpack.HeaderField{
"x-forwarded-for": []string{"host"}, pair("x-forwarded-for", "host"),
}, },
}) })
if err != nil { if err != nil {
...@@ -116,8 +117,8 @@ func TestHTTP2BadRequestCL(t *testing.T) { ...@@ -116,8 +117,8 @@ func TestHTTP2BadRequestCL(t *testing.T) {
res, err := st.http2(requestParam{ res, err := st.http2(requestParam{
name: "TestHTTP2BadRequestCL", name: "TestHTTP2BadRequestCL",
method: "POST", method: "POST",
header: http.Header{ header: []hpack.HeaderField{
"content-length": []string{"1024"}, pair("content-length", "1024"),
}, },
body: []byte("foo"), body: []byte("foo"),
}) })
......
...@@ -134,15 +134,14 @@ func (st *serverTester) readFrame() (http2.Frame, error) { ...@@ -134,15 +134,14 @@ func (st *serverTester) readFrame() (http2.Frame, error) {
} }
type requestParam struct { type requestParam struct {
name string // name for this request to identify the request name string // name for this request to identify the request in log easily
// in log easily streamID uint32 // stream ID, automatically assigned if 0
streamID uint32 // stream ID, automatically assigned if 0 method string // method, defaults to GET
method string // method, defaults to GET scheme string // scheme, defaults to http
scheme string // scheme, defaults to http authority string // authority, defaults to backend server address
authority string // authority, defaults to backend server address path string // path, defaults to /
path string // path, defaults to / header []hpack.HeaderField // additional request header fields
header http.Header // additional request header fields body []byte // request body
body []byte // request body
} }
func (st *serverTester) http2(rp requestParam) (*serverResponse, error) { func (st *serverTester) http2(rp requestParam) (*serverResponse, error) {
...@@ -195,10 +194,8 @@ 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)) _ = st.enc.WriteField(pair("test-case", rp.name))
for k, v := range rp.header { for _, h := range rp.header {
for _, h := range v { _ = st.enc.WriteField(pair(strings.ToLower(h.Name), h.Value))
_ = st.enc.WriteField(pair(strings.ToLower(k), h))
}
} }
err := st.fr.WriteHeaders(http2.HeadersFrameParam{ err := st.fr.WriteHeaders(http2.HeadersFrameParam{
......
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