// available.
ErrNotSupported = &ProtocolError{"feature not supported"}
- // ErrUnexpectedTrailer is returned by the Transport when a server
- // replies with a Trailer header, but without a chunked reply.
+ // Deprecated: ErrUnexpectedTrailer is no longer returned by
+ // anything in the net/http package. Callers should not
+ // compare errors against this variable.
ErrUnexpectedTrailer = &ProtocolError{"trailer header without chunked transfer encoding"}
// ErrMissingBoundary is returned by Request.MultipartReader when the
"Body here\ncontinued",
},
+ // Trailer header but no TransferEncoding
+ {
+ "HTTP/1.0 200 OK\r\n" +
+ "Trailer: Content-MD5, Content-Sources\r\n" +
+ "Content-Length: 10\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
+ Response{
+ Status: "200 OK",
+ StatusCode: 200,
+ Proto: "HTTP/1.0",
+ ProtoMajor: 1,
+ ProtoMinor: 0,
+ Request: dummyReq("GET"),
+ Header: Header{
+ "Connection": {"close"},
+ "Content-Length": {"10"},
+ "Trailer": []string{"Content-MD5, Content-Sources"},
+ },
+ Close: true,
+ ContentLength: 10,
+ },
+
+ "Body here\n",
+ },
+
// Chunked response with Content-Length.
{
"HTTP/1.1 200 OK\r\n" +
if !ok {
return nil, nil
}
+ if !chunked(te) {
+ // Trailer and no chunking:
+ // this is an invalid use case for trailer header.
+ // Nevertheless, no error will be returned and we
+ // let users decide if this is a valid HTTP message.
+ // The Trailer header will be kept in Response.Header
+ // but not populate Response.Trailer.
+ // See issue #27197.
+ return nil, nil
+ }
header.Del("Trailer")
trailer := make(Header)
if len(trailer) == 0 {
return nil, nil
}
- if !chunked(te) {
- // Trailer and no chunking
- return nil, ErrUnexpectedTrailer
- }
return trailer, nil
}