websocket 升级协议时的协议切换点

websocket 的 rfc6455 标准中提到了协议升级,从http协议升级到websocket协议,用的办法是在http的request header中包含Connection: upgrade 和 Upgrade: websocket 以及其他验证相关的头。服务器验证通过后发送 respond,并升级到websocket。但这儿有一个小问题,在rfc6455中并没有明确的提到,就是服务器在接收到http请求头之后,如何从文本格式切换到帧格式?这儿有没有一个明确的切换标志?在 rfc6455 中只明确提到使用 rfc2616 http/1.1 协议,在翻阅 rfc2616 之后,在4.1节 Message Types 中发现了这个标志:

Request (section 5) and Response (section 6) messages use the generic message format of RFC 822 [9] for transferring entities (the payload of the message). Both types of message consist of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.

generic-message = start-line *(message-header CRLF) CRLF [ message-body ] start-line = Request-Line | Status-Line

协议中提到在收到第一个空行之后,表示请求头结束,剩下的就是payload部分。而websocket由于是请求/响应协议升级,没有附带的payload,因此,可以确定的是,在收到连续的两个CRLF之后,表示文本部分结束,如果升级成功,则接下来传输的数据就是websocket 帧数据了。

相关推荐
大锦终5 分钟前
【Linux】HTTP协议
linux·运维·服务器·网络·http
biubiubiu070614 分钟前
网络科普:自治系统编号
网络·智能路由器
无聊的小坏坏3 小时前
详解 TCP 通信中的序列化与反序列化:从登录场景谈起
服务器·网络·tcp/ip
清山博客3 小时前
Springboot 局域网部署https解除安全警告
网络协议·安全·https
特种加菲猫4 小时前
自定义协议、序列化与守护进程:构建可靠后端服务
linux·网络·笔记
小楊不秃头4 小时前
网络原理:数据链路层、NAT与网页加载
网络·网络协议
The 旺4 小时前
【Rust实战】打造内存安全的网络代理:深入异步IO与并发编程
网络·安全·rust
jieyu11194 小时前
渗透测试中常见的网络端口
网络·渗透测试·端口
我叫汪枫5 小时前
《HTTP 的进化史:从 1.0 到 3.0 的飞跃》
网络·网络协议·http
我叫汪枫5 小时前
《拆解一封网络信:HTTP 报文详解》
网络·网络协议·http