reject requests with missing URL or Header in the RoundTripper

This commit is contained in:
Marten Seemann
2016-12-22 11:23:25 +07:00
parent 53706049c7
commit 1061bd4492
2 changed files with 61 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package h2quic
import (
"errors"
"net/http"
"sync"
)
@@ -30,6 +31,19 @@ var _ http.RoundTripper = &QuicRoundTripper{}
// RoundTrip does a round trip
func (r *QuicRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if req.URL == nil {
closeRequestBody(req)
return nil, errors.New("quic: nil Request.URL")
}
if req.URL.Host == "" {
closeRequestBody(req)
return nil, errors.New("quic: no Host in request URL")
}
if req.Header == nil {
closeRequestBody(req)
return nil, errors.New("quic: nil Request.Header")
}
hostname := authorityAddr("https", hostnameFromRequest(req))
client, err := r.getClient(hostname)
if err != nil {
@@ -61,3 +75,9 @@ func (r *QuicRoundTripper) getClient(hostname string) (h2quicClient, error) {
func (r *QuicRoundTripper) disableCompression() bool {
return r.DisableCompression
}
func closeRequestBody(req *http.Request) {
if req.Body != nil {
req.Body.Close()
}
}