Web套接字协议握手与交换协议 [英] Web Socket Protocol Handshake vs. Switching Protocols

查看:201
本文介绍了Web套接字协议握手与交换协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑。有人可以向我解释这两种响应状态之间的区别是什么:

I am a bit confused. Could somebody please explain to me 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 what response I get?

推荐答案

没有任何区别。重要的是 101 响应代码,表明握手正在进行中。这在 RFC 6455 中定义:

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:


客户端的主要行遵循请求行格式。 来自服务器的引导线遵循状态行格式。 Request-Line和Status-Line产品在[RFC2616]中定义。

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].

...

来自服务器的握手比客户端握手简单得多。 第一行是HTTP状态行,状态代码为101:

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切换协议

HTTP/1.1 101 Switching Protocols

除101之外的任何状态代码表示WebSocket握手尚未完成且HTTP的语义仍然适用。

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

Status-Line 的文本是任意的,服务器可以使用它想要的任何文本,每 RFC 2616

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


Status-Line = HTTP-Version SP状态码SP 原因 - 短语 CRLF

...

状态-Code元素是尝试理解和满足请求的3位整数结果代码。这些代码在第10节中完全定义。原因 - 短语旨在提供状态代码的简短文本描述。 Status-Code旨在供自动机使用, Reason-Phrase适用于人类用户。客户无需检查或显示Reason-Phrase。

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.

切换协议恰好是 RFC 6455 中使用的示例,但那是不是要求。

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

这篇关于Web套接字协议握手与交换协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆