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: TimeoutHandler: 200 OK should be sent if not specified #15948

Closed
h12w opened this issue Jun 3, 2016 · 1 comment

Comments

Projects
None yet
5 participants
@h12w
Copy link

commented Jun 3, 2016

What version of Go are you using (go version)?

1.6.2 and 1.4.3

What operating system and processor architecture are you using (go env)?

linux, amd64

What did you do?

Minimal example server (main.go):

package main

import (
    "log"
    "net/http"
    "time"
)

func main() {
    log.Fatal(http.ListenAndServe(":9999", http.TimeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    }), time.Second, "timeout")))
}

Then:

go run main.go
curl -i "http://127.0.0.1:9999"

What did you expect to see?

I expect 200 OK because it is consistent with the default behavior without the TimeoutHandler.

HTTP/1.1 200 OK
.......

What did you see instead?

HTTP/1.1 0 status code 0
......

Solution

In func (h *timeoutHandler) ServeHTTP in net/http/server.go, change the code from:

w.WriteHeader(tw.code)

To:

if tw.code == 0 {
    tw.code = StatusOK
}
w.WriteHeader(tw.code)

@ianlancetaylor ianlancetaylor changed the title net/http.TimeoutHandler: 200 OK should be sent if not specified net/http: TimeoutHandler: 200 OK should be sent if not specified Jun 3, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 3, 2016

@adg adg assigned adg and unassigned bradfitz Jun 6, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Jun 6, 2016

CL https://golang.org/cl/23810 mentions this issue.

@gopherbot gopherbot closed this in 3ba3155 Jun 6, 2016

@golang golang locked and limited conversation to collaborators Jun 6, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.