MCPcopy Create free account
hub / github.com/imroc/req / fixTrailer

Function fixTrailer

transfer.go:702–741  ·  view source on GitHub ↗

Parse the trailer header.

(header http.Header, chunked bool)

Source from the content-addressed store, hash-verified

700
701// Parse the trailer header.
702func fixTrailer(header http.Header, chunked bool) (http.Header, error) {
703 vv, ok := header["Trailer"]
704 if !ok {
705 return nil, nil
706 }
707 if !chunked {
708 // Trailer and no chunking:
709 // this is an invalid use case for trailer header.
710 // Nevertheless, no error will be returned and we
711 // let users decide if this is a valid HTTP message.
712 // The Trailer header will be kept in Response.Header
713 // but not populate Response.Trailer.
714 // See issue #27197.
715 return nil, nil
716 }
717 header.Del("Trailer")
718
719 trailer := make(http.Header)
720 var err error
721 for _, v := range vv {
722 foreachHeaderElement(v, func(key string) {
723 key = http.CanonicalHeaderKey(key)
724 switch key {
725 case "Transfer-Encoding", "Trailer", "Content-Length":
726 if err == nil {
727 err = badStringError("bad trailer key", key)
728 return
729 }
730 }
731 trailer[key] = nil
732 })
733 }
734 if err != nil {
735 return nil, err
736 }
737 if len(trailer) == 0 {
738 return nil, nil
739 }
740 return trailer, nil
741}
742
743// body turns a textprotoReader into a ReadCloser.
744// Close ensures that the body has been fully read

Callers 1

readTransferFunction · 0.85

Calls 2

badStringErrorFunction · 0.85
foreachHeaderElementFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…