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

相关推荐
zero_703212 分钟前
HCIP 课程文字版思维导图笔记
服务器·网络·php
NeilYuen1 小时前
实现TCP发送HTTP请求
网络协议·tcp/ip·http
天启HTTP2 小时前
爬虫频繁弹验证码?解析网站反爬检测机制
网络·爬虫·tcp/ip
jufeng13073 小时前
【系列:MiniKV 原理剖析 · 第 5 篇】
linux·网络·c++·软件工程
ARoger_miu573 小时前
opsf笔记
网络·网络协议
caimouse4 小时前
tcpip.sys 网络层 (IP) 详细分析
网络·网络协议·tcp/ip
草莓熊Lotso4 小时前
【Linux网络】从0手写Reactor反应堆(二):完善核心细节——ET非阻塞读写、分层架构与回调机制
linux·运维·服务器·网络·c++·tcp/ip·架构
驱动探索者4 小时前
RISC-V 指令集深度解析:从 ISA 到 Zephyr
网络·计算机·操作系统·os
agent8974 小时前
实战升级|SpringBoot WebSocket实现多轮对话AI流式问答(上下文记忆+自动重连+会话隔离)
人工智能·spring boot·websocket
wuhuhuan4 小时前
Day17:HTTP 接口测试与链式调用 — sendRequest 从入门到实战
网络·网络协议·http