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

相关推荐
Dream_ksw17 分钟前
借助AI再次理解三次握手和四次挥手
服务器·网络·tcp/ip
m0_738120721 小时前
渗透测试基础——PHP 序列化数据结构与反序列化机制详解
android·服务器·网络·数据结构·安全·php
myenjoy_11 小时前
采集网关的离线缓存与断点续传——当网络不可靠时,数据一条都不能丢
网络·缓存
超级无敌zhq1 小时前
内网横向移动实战:从单点攻破到域控沦陷
网络·安全·web安全·网络安全
LittleCoder6662 小时前
什么是双 SIM 冗余?工业路由器如何实现网络备份和故障切换
网络·智能路由器
炸炸鱼.2 小时前
Ansible 企业级实战:Playbook 与 Roles 完全指南
网络·ansible
网安小白的进阶之路2 小时前
B模块 安全通信网络 第二门课IPv6与WLAN 04
网络·安全·智能路由器
brycegao3212 小时前
金融交易App客户端架构实战 | 模块化、WebSocket治理、多线路容灾全解
websocket·金融·组件化·android架构·客户端模块化·移动端稳定性·多线路网络
yuanjj882 小时前
域格ASR平台cat1模块FTP上传、下载
运维·网络
比昨天多敲两行2 小时前
Linux 网络基础
网络