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: checking if http.Hijacker was already Hijacked without writing http.StatusOK #20331

Closed
wlredeye opened this issue May 11, 2017 · 1 comment

Comments

@wlredeye
Copy link

wlredeye commented May 11, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 darwin/amd64

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

macOS, amd64

What did you do?

I'm writing HTTP middleware that can check if underlying connection hijacked or not,
and if not - close connection with specific header and payload.
In go1.8 @bradfitz added some functionality to check if connection is hijacked without
unnecessary logs spam (#16456).
However, if connection is not hijacked, after call
_, err := w.Write(nil)
http.StatusOK is written automatically, so it's not possible to write any other header.

https://play.golang.org/p/LBnyyyijlk

So may be we can modify Write call to check if lenData == 0 before if !w.wroteHeader?
Or we need hijack checking interface anyway.

What did you expect to see?

nothing in logs

What did you see instead?

http: multiple response.WriteHeader calls

@bradfitz
Copy link
Contributor

Sorry, that would be too big of a breaking change for others.

You might be interested in #18997 which would provide a way for you to get the info you want.

@golang golang locked and limited conversation to collaborators May 11, 2018
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

3 participants