what is the benefit of using http hijacker
Asked Answered
O

1

6

Go http pkg provide a Hijacker interface, can anyone tell when should I use it.

I check the comment, after a Hijack call lets the caller take over the connection, the HTTP server library will not do anything else with the connection.

I understand it as it's used to support both http request and common tcp interactive within one port. Is it right? Does it has any other benefits.

Osithe answered 27/6, 2013 at 3:57 Comment(0)
E
18

It means that you take over the control of TCP connection. TCP is a generic transport protocol, whereas HTTP is an application protocol on top of TCP. The OSI seven layer model describes TCP as layer 4 and HTTP is layer 7.

If you need to implement a different application protocol, this is one use-case for hijacking.

Or if you need to do something specialised with HTTP, like preventing keep-alive connections, that is another use-case.

An example for an alternative web application protocol is Google's SPDY. It's also a good reason why you might hijack an existing HTTP connection, rather than create a TCP connection directly. For SPDY, a browser would first make an HTTP request that included 'accept' headers indicating that it is also able to understand SPDY. So now you could hijack the connection and implement SPDY instead of HTTP.

Escapade answered 27/6, 2013 at 8:33 Comment(2)
Why not make a tcp connection directly rather than hijack one from http connection?Osithe
like for SPDY, the client will do a http request, where he tells inside the header he will understand also SPDY, so you will hickjack this connection now, to send SPDY instead of httpEscapade

© 2022 - 2024 — McMap. All rights reserved.