aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/server.go
diff options
context:
space:
mode:
authorJames Tucker <raggi@google.com>2014-09-29 13:53:42 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2014-09-29 13:53:42 -0700
commit2da734189db9a7ad7d6de259ebe9003d20f9f291 (patch)
tree6b0f489af408c8b8488e720c34f07e89aa3a807a /src/net/http/server.go
parent705c1f5cd45d572ba32dea48f5fe997a9f970400 (diff)
downloadgo-2da734189db9a7ad7d6de259ebe9003d20f9f291.tar.xz
net/http: enable Transfer-Encoding: identity without Content-Length for HTTP 1.1.
Use case is SSE recommended configuration: http://www.w3.org/TR/eventsource/#notes Removes a TODO. LGTM=bradfitz R=golang-codereviews, bradfitz, tommi.virtanen CC=golang-codereviews https://golang.org/cl/100000044
Diffstat (limited to 'src/net/http/server.go')
-rw-r--r--src/net/http/server.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 7ad0bcbc20..b5959f7321 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -839,13 +839,20 @@ func (cw *chunkWriter) writeHeader(p []byte) {
} else if hasCL {
delHeader("Transfer-Encoding")
} else if w.req.ProtoAtLeast(1, 1) {
- // HTTP/1.1 or greater: use chunked transfer encoding
- // to avoid closing the connection at EOF.
- // TODO: this blows away any custom or stacked Transfer-Encoding they
- // might have set. Deal with that as need arises once we have a valid
- // use case.
- cw.chunking = true
- setHeader.transferEncoding = "chunked"
+ // HTTP/1.1 or greater: Transfer-Encoding has been set to identity, and no
+ // content-length has been provided. The connection must be closed after the
+ // reply is written, and no chunking is to be done. This is the setup
+ // recommended in the Server-Sent Events candidate recommendation 11,
+ // section 8.
+ if hasTE && te == "identity" {
+ cw.chunking = false
+ w.closeAfterReply = true
+ } else {
+ // HTTP/1.1 or greater: use chunked transfer encoding
+ // to avoid closing the connection at EOF.
+ cw.chunking = true
+ setHeader.transferEncoding = "chunked"
+ }
} else {
// HTTP version < 1.1: cannot do chunked transfer
// encoding and we don't know the Content-Length so