@@ -2019,6 +2019,22 @@ func (cs *clientStream) awaitFlowControl(maxBytes int) (taken int32, err error)
20192019 }
20202020}
20212021
2022+ func validateHeaders (hdrs http.Header ) string {
2023+ for k , vv := range hdrs {
2024+ if ! httpguts .ValidHeaderFieldName (k ) {
2025+ return fmt .Sprintf ("name %q" , k )
2026+ }
2027+ for _ , v := range vv {
2028+ if ! httpguts .ValidHeaderFieldValue (v ) {
2029+ // Don't include the value in the error,
2030+ // because it may be sensitive.
2031+ return fmt .Sprintf ("value for header %q" , k )
2032+ }
2033+ }
2034+ }
2035+ return ""
2036+ }
2037+
20222038var errNilRequestURL = errors .New ("http2: Request.URI is nil" )
20232039
20242040// requires cc.wmu be held.
@@ -2056,19 +2072,14 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
20562072 }
20572073 }
20582074
2059- // Check for any invalid headers and return an error before we
2075+ // Check for any invalid headers+trailers and return an error before we
20602076 // potentially pollute our hpack state. (We want to be able to
20612077 // continue to reuse the hpack encoder for future requests)
2062- for k , vv := range req .Header {
2063- if ! httpguts .ValidHeaderFieldName (k ) {
2064- return nil , fmt .Errorf ("invalid HTTP header name %q" , k )
2065- }
2066- for _ , v := range vv {
2067- if ! httpguts .ValidHeaderFieldValue (v ) {
2068- // Don't include the value in the error, because it may be sensitive.
2069- return nil , fmt .Errorf ("invalid HTTP header value for header %q" , k )
2070- }
2071- }
2078+ if err := validateHeaders (req .Header ); err != "" {
2079+ return nil , fmt .Errorf ("invalid HTTP header %s" , err )
2080+ }
2081+ if err := validateHeaders (req .Trailer ); err != "" {
2082+ return nil , fmt .Errorf ("invalid HTTP trailer %s" , err )
20722083 }
20732084
20742085 enumerateHeaders := func (f func (name , value string )) {
0 commit comments