英文:
what is the benefit of using http hijacker
问题
Go的http包提供了一个Hijacker接口,有人能告诉我什么时候应该使用它吗?
我查看了评论,发现在Hijack调用之后,调用者可以接管连接,HTTP服务器库将不会对连接做任何其他操作。
我理解它是用于在一个端口上同时支持HTTP请求和常见的TCP交互。这样理解对吗?它还有其他好处吗?
英文:
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.
答案1
得分: 18
这意味着你接管了TCP连接的控制权。
TCP是一种通用的传输协议,而HTTP是建立在TCP之上的应用协议。OSI七层模型将TCP描述为第4层,而HTTP是第7层。
如果你需要实现一个不同的应用协议,这就是劫持的一个用例。
或者如果你需要对HTTP进行一些特殊处理,比如阻止保持连接,那也是另一个用例。
一个替代的Web应用协议的例子是谷歌的SPDY。这也是为什么你可能会劫持现有的HTTP连接,而不是直接创建一个TCP连接的一个很好的理由。对于SPDY,浏览器首先会发出一个包含“accept”头的HTTP请求,指示它也能理解SPDY。现在你可以劫持连接并实现SPDY而不是HTTP。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论