Skip to content

net/http: treat HEAD methods less specially #5454

Closed
@bradfitz

Description

@bradfitz
Right now, a ResponseWriter Write will return ErrBodyNotAllowed for a HEAD request.

While some applications may want to check Request.Method == "HEAD" to avoid
some computation, the majority would prefer to be lazy.

For instance, see issue #5451 and the proposed fix
(https://golang.org/cl/9388043/) to shut up some bogus warnings:

        if err := godocHTML.Execute(w, page); err != nil && err != http.ErrBodyNotAllowed {
                log.Printf("godocHTML.Execute: %s", err)
    }

That means applications have to care about HEAD vs GET.

The server's default behavior should shield users from caring about HEAD and just do the
right thing, which means:

-- don't return ErrBodyNotAllowed for HEAD requests. (we'll still return it for other
cases)
-- still do Content-Type sniffing on first 512 bytes.
-- still count Content-Length and send that header, for bodies <= 2KB

Currently we don't do any of those 3, which means our response headers to HEAD requests
aren't the same as our responses to GET requests, unless the app goes out of its way to
do so, which most don't, since HEAD requests are rare.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeSuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions