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

相关推荐
Li_yizYa5 小时前
网络原理 | TCP协议的常见核心机制
网络·网络协议·tcp/ip
暮色_年华5 小时前
《TCP/IP协议卷1》第3章 IP协议
网络
galaxylove5 小时前
Gartner发布新的网络安全运营模型:决定安全运营的9个组件
网络·安全·web安全
老六ip加速器6 小时前
获取ip地址安全吗?如何获取静态ip地址隔离ip
运维·网络·智能路由器
领世达检测V133529092497 小时前
蓝牙戒指欧盟EN 18031网络安全认证详细解读
网络
王火火(DDoS CC防护)7 小时前
高防 IP 是如何帮助数藏行业防刷的
网络·网络协议·tcp/ip
神仙别闹7 小时前
基于 Matlab 和 Truetime 的网络控制系统仿真
网络·matlab·php
Johny_Zhao1 天前
CentOS Stream 8 高可用 Kuboard 部署方案
linux·网络·python·网络安全·docker·信息安全·kubernetes·云计算·shell·yum源·系统运维·kuboard
浪剑超1 天前
https说明
网络协议·http·https
uyeonashi1 天前
【QT系统相关】QT网络
开发语言·网络·c++·qt