Skip to content

net/http: checking if http.Hijacker was already Hijacked without writing http.StatusOK #20331

@wlredeye

Description

@wlredeye

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

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