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 帧数据了。

相关推荐
last demo2 小时前
fail2ban实验
linux·运维·服务器·网络
googleccsdn2 小时前
ENSP Pro Lab笔记:配置STP/RSTP/MSTP(7)
网络·笔记·网络协议
Fortinet_CHINA3 小时前
2026 年度 CISO 预测报告
网络·安全·ai
new_daimond3 小时前
WAF(Web Application Firewall)详解
网络·web app
ICT技术最前线4 小时前
如何高效搭建国际SD-WAN组网?
网络·sd-wan·sdwan·国际网络
不染尘.4 小时前
计算机网络评价指标和封包解包
服务器·网络·计算机网络
p***92484 小时前
Nginx location 和 proxy_pass 配置详解
服务器·网络·nginx
Macbethad5 小时前
DeviceNet主站程序技术方案
网络协议·信息与通信
米粒15 小时前
计算机通信与网络---网络层
网络
音视频牛哥5 小时前
GB/T 28181-2022深度技术解读:编码、传输、安全的全栈升级
网络·smartgbd·gb28181-2022·gb/t28181-2022·对接gb28181-2022·gb28181-2022升级·安卓gb28181对接