1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:34:48 -07:00

net/http: support mulit same transfer-encoding header

This commit is contained in:
Theo Sun 2021-02-24 15:31:15 +08:00
parent 6ba4a300d8
commit 0cd5bf000b
2 changed files with 12 additions and 1 deletions

View File

@ -636,7 +636,14 @@ func (t *transferReader) parseTransferEncoding() error {
// surfaces in HTTP/1.1 due to the risk of request smuggling, so we keep it
// strict and simple.
if len(raw) != 1 {
return &unsupportedTEError{fmt.Sprintf("too many transfer encodings: %q", raw)}
// support Transfer-Encoding: [chunked, chunked, chunked] for microservice remote call
uniqRaw := map[string]interface{}{}
for _, part := range raw {
uniqRaw[strings.ToLower(textproto.TrimString(part))] = nil
}
if len(uniqRaw) > 1 {
return &unsupportedTEError{fmt.Sprintf("too many transfer encodings: %q", raw)}
}
}
if strings.ToLower(textproto.TrimString(raw[0])) != "chunked" {
return &unsupportedTEError{fmt.Sprintf("unsupported transfer encoding: %q", raw[0])}

View File

@ -311,6 +311,10 @@ func TestParseTransferEncoding(t *testing.T) {
hdr: Header{"Transfer-Encoding": {"chunked"}},
wantErr: nil,
},
{
hdr: Header{"Transfer-Encoding": {"chunked", "chunked"}},
wantErr: nil,
},
}
for i, tt := range tests {