Gerrit Bot has uploaded this change for review.
net/http: support mulit same transfer-encoding header
Hello Golang STD Maintainers,
Here is a proposal about the `net/http/transfer`, we can discuss about this.
In my scenario, the java spring framework will allow application response result with duplicated `transfer-encoding` header, as a result, when the `go service` call the `java app`, the `go service` will raise an error about transfer-encoding.
so, as a result, I want to create a PR to make `go/net/http` could process response with duplicated `chunked` values in `tranfer-encoding` header.
Is that possible ?
Thanks
Change-Id: I21665745ac3a38dfddfc102ea85ba001c2037e7b
GitHub-Last-Rev: 0cd5bf000b7870c45cdc5253a8b56e50547ebb97
GitHub-Pull-Request: golang/go#44565
---
M src/net/http/transfer.go
M src/net/http/transfer_test.go
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go
index fbb0c39..9d7f4b7 100644
--- a/src/net/http/transfer.go
+++ b/src/net/http/transfer.go
@@ -636,7 +636,14 @@
// 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])}
diff --git a/src/net/http/transfer_test.go b/src/net/http/transfer_test.go
index f0c28b2..48911c0 100644
--- a/src/net/http/transfer_test.go
+++ b/src/net/http/transfer_test.go
@@ -311,6 +311,10 @@
hdr: Header{"Transfer-Encoding": {"chunked"}},
wantErr: nil,
},
+ {
+ hdr: Header{"Transfer-Encoding": {"chunked", "chunked"}},
+ wantErr: nil,
+ },
}
for i, tt := range tests {
To view, visit change 295829. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Brad Fitzpatrick.
Patch set 1:Code-Review +1
2 comments:
Patchset:
Let's see if getting a review on this gets it moving again…
File src/net/http/transfer.go:
Patch Set #1, Line 640: uniqRaw := map[string]interface{}{}
It is more idiomatic to represent a set as map[string]struct{} or map[string]bool.
But I wonder if it would be simpler to iterate over raw, and return an unsupportedTEError if any of the values isn't "chunked".
To view, visit change 295829. To unsubscribe, or for help writing mail filters, visit settings.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |