Skip to content

net/http: HEAD request doesn't populate Response.ContentLength  #4126

Closed
@bradfitz

Description

@bradfitz
If a handler replies to a HEAD request with a Content-Length field, the *Response
contains the "Content-Length: 1234" header, but the ContentLength field is
zero.

The docs say:

type Response struct {
...
    // ContentLength records the length of the associated content.  The
    // value -1 indicates that the length is unknown.  Unless RequestMethod
    // is "HEAD", values >= 0 indicate that the given number of bytes may
    // be read from Body.
    ContentLength int64
}

... suggesting that we should be setting it when we know it.

Related, Response.Write should write the correct length.  Currently the one in the
header map is being ignored in favor of the zero.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions