Web Socket Protocol Handshake vs. Switching Protocols

做~自己de王妃 提交于 2019-12-20 10:39:05

问题


What's the difference between these two response statuses:

HTTP/1.1 101 Web Socket Protocol Handshake

HTTP/1.1 101 Switching Protocols

Does it matter which one I get?


回答1:


There is no difference whatsoever. What is important is the 101 response code to indicate the handshake is progressing. This is defined in RFC 6455:

The leading line from the client follows the Request-Line format. The leading line from the server follows the Status-Line format. The Request-Line and Status-Line productions are defined in [RFC2616].

...

The handshake from the server is much simpler than the client handshake. The first line is an HTTP Status-Line, with the status code 101:

HTTP/1.1 101 Switching Protocols

Any status code other than 101 indicates that the WebSocket handshake has not completed and that the semantics of HTTP still apply.

The text of the Status-Line is arbitrary, the server can use whatever text it wants, per RFC 2616:

Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

...

The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. These codes are fully defined in section 10. The Reason-Phrase is intended to give a short textual description of the Status-Code. The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason-Phrase.

Switching Protocols just happens to be what the examples in RFC 6455 use, but that is not a requirement.



来源:https://stackoverflow.com/questions/22410903/web-socket-protocol-handshake-vs-switching-protocols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!