mirror of
https://github.com/golang/go
synced 2024-11-17 02:54:45 -07:00
net/http/httptest: allow multiple fields be present in one Trailer field
Fixes #51761 Change-Id: Ibaa17076ba51b666e25333e78180b8c7c4c940ec Reviewed-on: https://go-review.googlesource.com/c/go/+/393616 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
ea7e3e3c0f
commit
ff14e844d2
@ -207,18 +207,20 @@ func (rw *ResponseRecorder) Result() *http.Response {
|
||||
if trailers, ok := rw.snapHeader["Trailer"]; ok {
|
||||
res.Trailer = make(http.Header, len(trailers))
|
||||
for _, k := range trailers {
|
||||
k = http.CanonicalHeaderKey(k)
|
||||
if !httpguts.ValidTrailerHeader(k) {
|
||||
// Ignore since forbidden by RFC 7230, section 4.1.2.
|
||||
continue
|
||||
for _, k := range strings.Split(k, ",") {
|
||||
k = http.CanonicalHeaderKey(textproto.TrimString(k))
|
||||
if !httpguts.ValidTrailerHeader(k) {
|
||||
// Ignore since forbidden by RFC 7230, section 4.1.2.
|
||||
continue
|
||||
}
|
||||
vv, ok := rw.HeaderMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
vv2 := make([]string, len(vv))
|
||||
copy(vv2, vv)
|
||||
res.Trailer[k] = vv2
|
||||
}
|
||||
vv, ok := rw.HeaderMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
vv2 := make([]string, len(vv))
|
||||
copy(vv2, vv)
|
||||
res.Trailer[k] = vv2
|
||||
}
|
||||
}
|
||||
for k, vv := range rw.HeaderMap {
|
||||
|
@ -220,8 +220,7 @@ func TestRecorder(t *testing.T) {
|
||||
"Trailer headers are correctly recorded",
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Non-Trailer", "correct")
|
||||
w.Header().Set("Trailer", "Trailer-A")
|
||||
w.Header().Add("Trailer", "Trailer-B")
|
||||
w.Header().Set("Trailer", "Trailer-A, Trailer-B")
|
||||
w.Header().Add("Trailer", "Trailer-C")
|
||||
io.WriteString(w, "<html>")
|
||||
w.Header().Set("Non-Trailer", "incorrect")
|
||||
|
Loading…
Reference in New Issue
Block a user