concatenate Cookie HPACK headers for the HTTP request

fixes #338
This commit is contained in:
Marten Seemann
2016-10-30 12:13:01 +07:00
committed by Lucas Clemente
parent bb24be8281
commit 76cf0a2345
2 changed files with 21 additions and 0 deletions

View File

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

View File

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