http3: simplify if condition in roundtripper (#3658)

Signed-off-by: Avi Rosenberg <avrumi96@gmail.com>

Signed-off-by: Avi Rosenberg <avrumi96@gmail.com>
This commit is contained in:
Avi Rosenberg 2023-01-01 22:20:44 +02:00 committed by GitHub
parent d2512193da
commit cf1aff0492
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,22 +110,20 @@ func (r *RoundTripper) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.
closeRequestBody(req)
return nil, errors.New("http3: nil Request.Header")
}
if req.URL.Scheme == "https" {
for k, vv := range req.Header {
if !httpguts.ValidHeaderFieldName(k) {
return nil, fmt.Errorf("http3: invalid http header field name %q", k)
}
for _, v := range vv {
if !httpguts.ValidHeaderFieldValue(v) {
return nil, fmt.Errorf("http3: invalid http header field value %q for key %v", v, k)
}
}
}
} else {
if req.URL.Scheme != "https" {
closeRequestBody(req)
return nil, fmt.Errorf("http3: unsupported protocol scheme: %s", req.URL.Scheme)
}
for k, vv := range req.Header {
if !httpguts.ValidHeaderFieldName(k) {
return nil, fmt.Errorf("http3: invalid http header field name %q", k)
}
for _, v := range vv {
if !httpguts.ValidHeaderFieldValue(v) {
return nil, fmt.Errorf("http3: invalid http header field value %q for key %v", v, k)
}
}
}
if req.Method != "" && !validMethod(req.Method) {
closeRequestBody(req)