diff --git a/h2quic/request.go b/h2quic/request.go index fcd57ff5..7bcebda7 100644 --- a/h2quic/request.go +++ b/h2quic/request.go @@ -5,6 +5,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "golang.org/x/net/http2/hpack" ) @@ -30,6 +31,11 @@ func requestFromHeaders(headers []hpack.HeaderField) (*http.Request, error) { } } + // concatenate cookie headers, see https://tools.ietf.org/html/rfc6265#section-5.4 + if len(httpHeaders["Cookie"]) > 0 { + httpHeaders.Set("Cookie", strings.Join(httpHeaders["Cookie"], "; ")) + } + if len(path) == 0 || len(authority) == 0 || len(method) == 0 { return nil, errors.New(":path, :authority and :method must not be empty") } diff --git a/h2quic/request_test.go b/h2quic/request_test.go index f327cb2b..1b35f1aa 100644 --- a/h2quic/request_test.go +++ b/h2quic/request_test.go @@ -31,6 +31,21 @@ var _ = Describe("Request", func() { Expect(req.RequestURI).To(Equal("/foo")) }) + It("concatenates the cookie headers", func() { + headers := []hpack.HeaderField{ + {Name: ":path", Value: "/foo"}, + {Name: ":authority", Value: "quic.clemente.io"}, + {Name: ":method", Value: "GET"}, + {Name: "cookie", Value: "cookie1=foobar1"}, + {Name: "cookie", Value: "cookie2=foobar2"}, + } + req, err := requestFromHeaders(headers) + Expect(err).NotTo(HaveOccurred()) + Expect(req.Header).To(Equal(http.Header{ + "Cookie": []string{"cookie1=foobar1; cookie2=foobar2"}, + })) + }) + It("handles other headers", func() { headers := []hpack.HeaderField{ {Name: ":path", Value: "/foo"},