forked from quic-go/quic-go
add support for the HTTP CONNECT method (#2761)
This commit is contained in:
@@ -37,13 +37,28 @@ func requestFromHeaders(headers []qpack.HeaderField) (*http.Request, error) {
|
||||
httpHeaders.Set("Cookie", strings.Join(httpHeaders["Cookie"], "; "))
|
||||
}
|
||||
|
||||
if len(path) == 0 || len(authority) == 0 || len(method) == 0 {
|
||||
isConnect := method == http.MethodConnect
|
||||
if isConnect {
|
||||
if path != "" || authority == "" {
|
||||
return nil, errors.New(":path must be empty and :authority must not be empty")
|
||||
}
|
||||
} else if len(path) == 0 || len(authority) == 0 || len(method) == 0 {
|
||||
return nil, errors.New(":path, :authority and :method must not be empty")
|
||||
}
|
||||
|
||||
u, err := url.ParseRequestURI(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var u *url.URL
|
||||
var requestURI string
|
||||
var err error
|
||||
|
||||
if isConnect {
|
||||
u = &url.URL{Host: authority}
|
||||
requestURI = authority
|
||||
} else {
|
||||
u, err = url.ParseRequestURI(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requestURI = path
|
||||
}
|
||||
|
||||
var contentLength int64
|
||||
@@ -64,7 +79,7 @@ func requestFromHeaders(headers []qpack.HeaderField) (*http.Request, error) {
|
||||
Body: nil,
|
||||
ContentLength: contentLength,
|
||||
Host: authority,
|
||||
RequestURI: path,
|
||||
RequestURI: requestURI,
|
||||
TLS: &tls.ConnectionState{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -81,6 +81,17 @@ var _ = Describe("Request", func() {
|
||||
}))
|
||||
})
|
||||
|
||||
It("handles CONNECT method", func() {
|
||||
headers := []qpack.HeaderField{
|
||||
{Name: ":authority", Value: "quic.clemente.io"},
|
||||
{Name: ":method", Value: http.MethodConnect},
|
||||
}
|
||||
req, err := requestFromHeaders(headers)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(req.Method).To(Equal(http.MethodConnect))
|
||||
Expect(req.RequestURI).To(Equal("quic.clemente.io"))
|
||||
})
|
||||
|
||||
It("errors with missing path", func() {
|
||||
headers := []qpack.HeaderField{
|
||||
{Name: ":authority", Value: "quic.clemente.io"},
|
||||
@@ -108,6 +119,24 @@ var _ = Describe("Request", func() {
|
||||
Expect(err).To(MatchError(":path, :authority and :method must not be empty"))
|
||||
})
|
||||
|
||||
It("errors with missing authority in CONNECT method", func() {
|
||||
headers := []qpack.HeaderField{
|
||||
{Name: ":method", Value: http.MethodConnect},
|
||||
}
|
||||
_, err := requestFromHeaders(headers)
|
||||
Expect(err).To(MatchError(":path must be empty and :authority must not be empty"))
|
||||
})
|
||||
|
||||
It("errors with extra path in CONNECT method", func() {
|
||||
headers := []qpack.HeaderField{
|
||||
{Name: ":path", Value: "/foo"},
|
||||
{Name: ":authority", Value: "quic.clemente.io"},
|
||||
{Name: ":method", Value: http.MethodConnect},
|
||||
}
|
||||
_, err := requestFromHeaders(headers)
|
||||
Expect(err).To(MatchError(":path must be empty and :authority must not be empty"))
|
||||
})
|
||||
|
||||
Context("extracting the hostname from a request", func() {
|
||||
var url *url.URL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user