Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: HTTP/1.0 keep-alive request to non-writing handler should set Content-Length 0 #4004

Closed
bradfitz opened this issue Aug 24, 2012 · 1 comment

Comments

@bradfitz
Copy link
Contributor

For an HTTP handler with no writes in its handler,


package main

import (
    "net/http"
    "log"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    })
    log.Fatal(http.ListenAndServe(":8080", nil))
}

... we don't deal with HTTP/1.0 requests with "Connection: keep-alive" ideally.

If we set a Content-Length: 0 header here, we wouldn't have to close the connection:

$ telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Connetion: keep-alive

HTTP/1.0 200 OK
Connection: close
Date: Fri, 24 Aug 2012 19:53:36 GMT
Content-Type: text/plain; charset=utf-8

Connection closed by foreign host.



We do the right thing for HTTP/1.1 (sending a chunked response and closing the chunk
stream).
@bradfitz
Copy link
Contributor Author

Comment 1:

This issue was closed by revision 49f29c9.

Status changed to Fixed.

@bradfitz bradfitz added the fixed label Aug 26, 2012
@bradfitz bradfitz self-assigned this Aug 26, 2012
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants