go/src/pkg/net/http
Brad Fitzpatrick ebe91d1105 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 #5454

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12583043
2013-08-06 18:33:03 -07:00
..
cgi undo CL 12486043 / ab644299d124 2013-08-05 16:27:24 -07:00
cookiejar all: be more idiomatic when documenting boolean return values. 2013-07-23 11:59:49 +10:00
fcgi net/http/fcgi: fix a shutdown race 2013-03-21 14:07:24 -07:00
httptest net/http/httptest: fix incorrectly-named ResponseRecorder example 2013-04-29 17:34:47 +02:00
httputil build: remove dead code 2013-03-22 17:28:22 -04:00
pprof bytes, strings: add TrimPrefix and TrimSuffix 2013-02-01 08:41:25 -08:00
testdata
chunked.go net/http: remove more garbage from chunk reading 2012-11-19 19:50:42 -08:00
chunked_test.go net/http, net/http/httputil: fix TestChunkReaderAllocs failure when GOMAXPROCS > 1 2012-11-21 02:18:34 +08:00
client.go net/http: document and test Client.Post treating Reader body as ReadCloser 2013-07-19 12:02:54 +10:00
client_test.go net/http: respect tls.Config.ServerName in Transport 2013-07-22 22:39:09 -07:00
cookie.go undo CL 12486043 / ab644299d124 2013-08-05 16:27:24 -07:00
cookie_test.go net/http: don't write out invalid cookie lines 2013-08-01 12:16:37 -07:00
doc.go
example_test.go net/http: better stand-alone FileServer doc example 2013-04-04 13:40:15 -07:00
export_test.go net/http: fix memory leak in Transport 2013-06-28 12:57:54 -07:00
filetransport.go
filetransport_test.go net/http: fix a bunch of test leaks 2013-02-26 17:12:50 -08:00
fs.go undo CL 12486043 / ab644299d124 2013-08-05 16:27:24 -07:00
fs_test.go net/http: skip TestDirJoin on Windows, even if /etc/hosts exists 2013-07-30 18:25:08 -07:00
header.go all: be more idiomatic when documenting boolean return values. 2013-07-23 11:59:49 +10:00
header_test.go all: Skip AllocsPerRun tests if GOMAXPROCS>1. 2013-03-06 15:52:32 -08:00
jar.go net/http: document net/http/cookiejar on CookieJar 2013-02-28 16:58:14 -08:00
lex.go
lex_test.go
npn_test.go net/http: add Next Protocol Negotation upgrade support to the Server 2013-02-04 13:55:38 -08:00
proxy_test.go net/http: match curl and others' NO_PROXY wildcard handling 2012-12-22 17:41:00 -08:00
range_test.go net/http: support multiple byte ranges in ServeContent 2012-06-29 07:44:04 -07:00
readrequest_test.go net/http, net/url: permit Request-URI "*" 2012-12-11 12:07:27 -05:00
request.go undo CL 12486043 / ab644299d124 2013-08-05 16:27:24 -07:00
request_test.go net/http: add tests for ParseHTTPVersion 2013-03-12 11:18:18 +11:00
requestwrite_test.go net/http: add a test verifying header case preservation 2013-03-11 11:10:43 -07:00
response.go net/http: fix Response.Header documentation for multiple headers with same key 2013-08-04 11:23:17 -07:00
response_test.go net/http: Transport should return an error when response body ends early 2013-06-24 13:27:56 -07:00
responsewrite_test.go all: make tests able to run multiple times. 2013-01-27 00:24:09 +01:00
serve_test.go net/http: treat HEAD requests like GET requests 2013-08-06 18:33:03 -07:00
server.go net/http: treat HEAD requests like GET requests 2013-08-06 18:33:03 -07:00
server_test.go net/http: fix a panic in Redirect 2013-04-20 17:20:14 -07:00
sniff.go
sniff_test.go net/http: don't MIME sniff if handler set an empty string Content-Type 2013-07-31 23:38:32 -07:00
status.go net/http: add additional status codes defined in RFC 6585 2013-03-11 07:43:57 -07:00
transfer.go all: be more idiomatic when documenting boolean return values. 2013-07-23 11:59:49 +10:00
transfer_test.go archive/zip, crypto/tls, net/http: Fix print format errors. 2012-11-16 17:24:43 -08:00
transport.go net/http: respect tls.Config.ServerName in Transport 2013-07-22 22:39:09 -07:00
transport_test.go net/http: treat HEAD requests like GET requests 2013-08-06 18:33:03 -07:00
triv.go
z_last_test.go net/http: make CloseNotifier channel buffered to not leak goroutines 2013-04-22 10:32:10 -07:00