http3: deduplicate Content-Length headers (#3972)

This commit is contained in:
Marten Seemann
2023-07-18 21:52:21 -07:00
committed by GitHub
parent bb296b8c17
commit 5d59c3059f
2 changed files with 35 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ type header struct {
func parseHeaders(headers []qpack.HeaderField, isRequest bool) (header, error) {
hdr := header{Headers: make(http.Header, len(headers))}
var readFirstRegularHeader bool
var readFirstRegularHeader, readContentLength bool
var contentLengthStr string
for _, h := range headers {
// field names need to be lowercase, see section 4.2 of RFC 9114
@@ -74,7 +74,14 @@ func parseHeaders(headers []qpack.HeaderField, isRequest bool) (header, error) {
readFirstRegularHeader = true
switch h.Name {
case "content-length":
contentLengthStr = h.Value
// Ignore duplicate Content-Length headers.
// Fail if the duplicates differ.
if !readContentLength {
readContentLength = true
contentLengthStr = h.Value
} else if contentLengthStr != h.Value {
return header{}, fmt.Errorf("contradicting content lengths (%s and %s)", contentLengthStr, h.Value)
}
default:
hdr.Headers.Add(h.Name, h.Value)
}