Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(566)

Issue 12583043: code review 12583043: net/http: treat HEAD requests like GET requests (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 9 months ago by bradfitz
Modified:
10 years, 9 months ago
Reviewers:
dsymonds
CC:
golang-dev, dsymonds
Visibility:
Public.

Description

net/http: treat HEAD requests like GET requests A response to a HEAD request is supposed to look the same as a response to a GET request, just without a body. HEAD requests are incredibly rare in the wild. The Go net/http package has so far treated HEAD requests specially: a Write on our default ResponseWriter returned ErrBodyNotAllowed, telling handlers that something was wrong. This was to optimize the fast path for HEAD requests, but: 1) because HEAD requests are incredibly rare, they're not worth having a fast path for. 2) Letting the http.Handler handle but do nop Writes is still very fast. 3) this forces ugly error handling into the application. e.g. https://code.google.com/p/go/source/detail?r=6f596be7a31e and related. 4) The net/http package nowadays does Content-Type sniffing, but you don't get that for HEAD. 5) The net/http package nowadays does Content-Length counting for small (few KB) responses, but not for HEAD. 6) ErrBodyNotAllowed was useless. By the time you received it, you had probably already done all your heavy computation and I/O to calculate what to write. So, this change makes HEAD requests like GET requests. We now count content-length and sniff content-type for HEAD requests. If you Write, it doesn't return an error. If you want a fast-path in your code for HEAD, you have to do it early and set all the response headers yourself. Just like before. If you choose not to Write in HEAD requests, be sure to set Content-Length if you know it. We won't write "Content-Length: 0" because you might've just chosen to not write (or you don't know your Content-Length in advance). Fixes issue 5454

Patch Set 1 #

Patch Set 2 : diff -r 626c01d29570 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 626c01d29570 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 4 : diff -r 2fb249d994cb https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+29 lines, -18 lines) Patch
M src/pkg/net/http/serve_test.go View 1 2 chunks +13 lines, -13 lines 0 comments Download
M src/pkg/net/http/server.go View 1 7 chunks +10 lines, -5 lines 0 comments Download
M src/pkg/net/http/transport_test.go View 1 2 chunks +6 lines, -0 lines 0 comments Download

Messages

Total messages: 8
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
10 years, 9 months ago (2013-08-07 00:52:12 UTC) #1
dsymonds
LGTM I'm a little rusty on this code these days, but it looks sane. Just ...
10 years, 9 months ago (2013-08-07 01:01:47 UTC) #2
bradfitz
On Tue, Aug 6, 2013 at 6:01 PM, <dsymonds@golang.org> wrote: > LGTM > > I'm ...
10 years, 9 months ago (2013-08-07 01:06:50 UTC) #3
bradfitz
On Tue, Aug 6, 2013 at 6:06 PM, Brad Fitzpatrick <bradfitz@golang.org>wrote: > > > > ...
10 years, 9 months ago (2013-08-07 01:07:21 UTC) #4
dsymonds
On 7 August 2013 11:06, Brad Fitzpatrick <bradfitz@golang.org> wrote: > We do want a Content-Length ...
10 years, 9 months ago (2013-08-07 01:18:18 UTC) #5
bradfitz
On Tue, Aug 6, 2013 at 6:18 PM, David Symonds <dsymonds@golang.org> wrote: > On 7 ...
10 years, 9 months ago (2013-08-07 01:29:03 UTC) #6
bradfitz
*** Submitted as https://code.google.com/p/go/source/detail?r=3a388be1862e *** net/http: treat HEAD requests like GET requests A response to ...
10 years, 9 months ago (2013-08-07 01:33:08 UTC) #7
dsymonds
10 years, 9 months ago (2013-08-07 01:53:01 UTC) #8
LGTM
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b