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

相关推荐
conkl7 分钟前
构建健壮的前端请求体系:从 HTTP 状态码到 Axios 实战
前端·网络协议·http
北京盛世宏博30 分钟前
如何利用技术手段来甄选一套档案馆库房安全温湿度监控系统
服务器·网络·人工智能·选择·档案温湿度
濊繵2 小时前
Linux网络--Socket 编程 TCP
linux·网络·tcp/ip
menge23332 小时前
Linux网站搭建
linux·运维·网络
2301_821727173 小时前
nfs服务
网络·笔记
老蒋新思维3 小时前
紧跟郑滢轩,以 “学习力 +” 驱动 AI 与 IP 商业变革
网络·人工智能·学习·tcp/ip·企业管理·创始人ip·创客匠人
AIwenIPgeolocation4 小时前
IP种子技术:构建全球P2P网络实时监测方案
网络·tcp/ip·p2p
Ace_31750887764 小时前
拼多多关键字搜索接口逆向:从 WebSocket 实时推送解析到商品数据结构化重建
数据结构·websocket·网络协议
小二·4 小时前
TCP/UDP/Socket/HTTP 网络编程高频面试题(47道 + 详细答案)
网络·tcp/ip·udp
清空mega4 小时前
第11章 网络编程
android·网络