From de2c1f9cb8314631d7112722aabed549c9606bbd Mon Sep 17 00:00:00 2001 From: Rangel Ivanov Date: Tue, 14 May 2019 10:06:13 +0300 Subject: [PATCH] http3/request: Fix URL parsing of leading double slashes after authority Use url.ParseRequestURI instead of url.Parse. Otherwise it will be interpreted as a path without a scheme which will result in '//some_path' parsed as url.Host:somepath and empty url.Path --- http3/request.go | 2 +- http3/request_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/http3/request.go b/http3/request.go index 962ae1e56..7036cc371 100644 --- a/http3/request.go +++ b/http3/request.go @@ -41,7 +41,7 @@ func requestFromHeaders(headers []qpack.HeaderField) (*http.Request, error) { return nil, errors.New(":path, :authority and :method must not be empty") } - u, err := url.Parse(path) + u, err := url.ParseRequestURI(path) if err != nil { return nil, err } diff --git a/http3/request_test.go b/http3/request_test.go index 1ca2cf570..251e324e4 100644 --- a/http3/request_test.go +++ b/http3/request_test.go @@ -21,6 +21,7 @@ var _ = Describe("Request", func() { Expect(err).NotTo(HaveOccurred()) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Path).To(Equal("/foo")) + Expect(req.URL.Host).To(BeEmpty()) Expect(req.Proto).To(Equal("HTTP/3")) Expect(req.ProtoMajor).To(Equal(3)) Expect(req.ProtoMinor).To(BeZero()) @@ -32,6 +33,22 @@ var _ = Describe("Request", func() { Expect(req.TLS).ToNot(BeNil()) }) + It("parses path with leading double slashes", func() { + headers := []qpack.HeaderField{ + {Name: ":path", Value: "//foo"}, + {Name: ":authority", Value: "quic.clemente.io"}, + {Name: ":method", Value: "GET"}, + } + req, err := requestFromHeaders(headers) + Expect(err).NotTo(HaveOccurred()) + Expect(req.Header).To(BeEmpty()) + Expect(req.Body).To(BeNil()) + Expect(req.URL.Path).To(Equal("//foo")) + Expect(req.URL.Host).To(BeEmpty()) + Expect(req.Host).To(Equal("quic.clemente.io")) + Expect(req.RequestURI).To(Equal("//foo")) + }) + It("concatenates the cookie headers", func() { headers := []qpack.HeaderField{ {Name: ":path", Value: "/foo"},