You can see one library (martini) which introduced hijack
: issue 45
(Note: I don't recommend Martini, which is not idiomatic, but it is mentioned here only to illustrate hijack
)
Would it be possible for your responseWriter type to implement http.Hijack?
This would allow libraries like this websockets one to work with martini.
That issue refers to the following go-nuts thread, where one tried to embed the interface http.ResponseWriter
in order to record statistics like bytes written and request duration.
Later on somebody pointed out some other interesting features of the http library, such as the CloseNotifier
interface, and I realized the above code might not be such a good idea.
Since I'm embedding an interface, I can't automatically inherit *http.Response
's implementations of CloseNotifier
and Flusher
.
So, if you want to take over the ResponseWriter
in order to:
- record more information (status, size, ..., calling hijack is probably overkill here),
- implement another protocol (like websocket, which "
Upgrade
" an HTTP server connection, calling w.(http.Hijacker)
)
Then you can consider using hijack.
But, as documented, after a call to Hijack()
, the HTTP server library will not do anything else with the connection.
It becomes the caller's responsibility to manage and close the connection.
If not, as illustrating in this other question, then hijack isn't interesting.