forked from quic-go/quic-go
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
This commit is contained in:
@@ -41,7 +41,7 @@ func requestFromHeaders(headers []qpack.HeaderField) (*http.Request, error) {
|
|||||||
return nil, errors.New(":path, :authority and :method must not be empty")
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ var _ = Describe("Request", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(req.Method).To(Equal("GET"))
|
Expect(req.Method).To(Equal("GET"))
|
||||||
Expect(req.URL.Path).To(Equal("/foo"))
|
Expect(req.URL.Path).To(Equal("/foo"))
|
||||||
|
Expect(req.URL.Host).To(BeEmpty())
|
||||||
Expect(req.Proto).To(Equal("HTTP/3"))
|
Expect(req.Proto).To(Equal("HTTP/3"))
|
||||||
Expect(req.ProtoMajor).To(Equal(3))
|
Expect(req.ProtoMajor).To(Equal(3))
|
||||||
Expect(req.ProtoMinor).To(BeZero())
|
Expect(req.ProtoMinor).To(BeZero())
|
||||||
@@ -32,6 +33,22 @@ var _ = Describe("Request", func() {
|
|||||||
Expect(req.TLS).ToNot(BeNil())
|
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() {
|
It("concatenates the cookie headers", func() {
|
||||||
headers := []qpack.HeaderField{
|
headers := []qpack.HeaderField{
|
||||||
{Name: ":path", Value: "/foo"},
|
{Name: ":path", Value: "/foo"},
|
||||||
|
|||||||
Reference in New Issue
Block a user