Skip to content

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

Closed
@bradfitz

Description

@bradfitz
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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions