diff options
| author | Russ Cox <rsc@golang.org> | 2011-01-13 14:34:31 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-01-13 14:34:31 -0500 |
| commit | cdb0bbf4d55f772283de42364d9d154ce42e8dd0 (patch) | |
| tree | c22a2a90bdcb9b6abed8f8e2ba0a872ab024ffc5 /src/pkg/http/server.go | |
| parent | 97025ebfef22363efd3ece2fac302c4e0efc1893 (diff) | |
| download | go-cdb0bbf4d55f772283de42364d9d154ce42e8dd0.tar.xz | |
http: handle HEAD requests correctly
R=r, r2
CC=golang-dev
https://golang.org/cl/3939042
Diffstat (limited to 'src/pkg/http/server.go')
| -rw-r--r-- | src/pkg/http/server.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index b8783da283..2ecdd5ee25 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -181,7 +181,9 @@ func (c *conn) readRequest() (w *response, err os.Error) { w.SetHeader("Content-Type", "text/html; charset=utf-8") w.SetHeader("Date", time.UTC().Format(TimeFormat)) - if req.ProtoAtLeast(1, 1) { + if req.Method == "HEAD" { + // do nothing + } else if req.ProtoAtLeast(1, 1) { // HTTP/1.1 or greater: use chunked transfer encoding // to avoid closing the connection at EOF. w.chunking = true @@ -268,7 +270,7 @@ func (w *response) Write(data []byte) (n int, err os.Error) { return 0, nil } - if w.status == StatusNotModified { + if w.status == StatusNotModified || w.req.Method == "HEAD" { // Must not have body. return 0, ErrBodyNotAllowed } @@ -495,11 +497,11 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) { // RFC2616 recommends that a short note "SHOULD" be included in the // response because older user agents may not understand 301/307. - note := "<a href=\"" + htmlEscape(url) + "\">" + statusText[code] + "</a>.\n" - if r.Method == "POST" { - note = "" + // Shouldn't send the response for POST or HEAD; that leaves GET. + if r.Method == "GET" { + note := "<a href=\"" + htmlEscape(url) + "\">" + statusText[code] + "</a>.\n" + fmt.Fprintln(w, note) } - fmt.Fprintln(w, note) } func htmlEscape(s string) string { |
