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 {
"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")