gobwas / ws

Tiny WebSocket library for Go.
MIT License
6.12k stars 376 forks source link

added a Hijack Route for upgrade #159

Open barkyq opened 1 year ago

barkyq commented 1 year ago

Hello Gobwas,

Thanks for the great package. I was hoping to add an option to "hijack" the upgrade process if a certain header was present, cancelling the upgrade negotiation and handing back control to the caller of "Upgrade," without writing anything to the "Conn."

My idea was to use status code "418" http.StatusTeapot, defined in https://www.rfc-editor.org/rfc/rfc2324 as a signal that the user wants to Hijack the handshake process.

This is to implement https://github.com/nostr-protocol/nips/blob/master/11.md in a project I am working on.

Sincerely, Barky Q

barkyq commented 1 year ago

changed the logic from the initial commit. now it is called escape hatch.

With this way, the upgrader can see all the non-ws headers and store any relevant information in the error pointer, which gets passed around to each call of OnHost and OnHeader.