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

相关推荐
mitugaoyang19933 小时前
marvell88Q5152交换机开发(0)-芯片介绍
网络
CDN3603 小时前
流媒体加速实践:出海东南亚短视频点播频繁缓冲,HLS 分片与 Nginx 配置调优
java·网络·nginx·流媒体加速
xiaoxiangsiyan3 小时前
RHCE2026完整版全知识点清单
运维·网络·学习·自动化·rhce
AlanBruce4 小时前
摩尔信使MThings新功能:水电不分家、一键设备扫描
网络·自动化·plc·mthings·摩尔信使·电气·西门子s7
Titan20244 小时前
Linux网络基础知识
linux·服务器·网络·c++·学习
RisunJan6 小时前
Linux命令-tcpdump(网络数据包捕获)
linux·网络·tcpdump
Titan20246 小时前
Linux网络学习:套接字、UDP的封装与应用
linux·服务器·开发语言·网络·c++
啦啦啦啦啦zzzz8 小时前
TCP协议详解
网络·网络协议·tcp/ip
jason.zeng@15022079 小时前
服务器磁盘读写效率,网络吞吐量查看,mysql性能调优
服务器·网络·mysql
张小姐的猫9 小时前
【Linux】网络编程 —— 传输层协议 TCP(下)
linux·运维·服务器·网络·tcp/ip·http·php