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

相关推荐
想你依然心痛1 小时前
RT-Thread组件生态:SAL网络框架与AT组件实战——网络抽象、AT指令
网络·arm开发·at·sal
2401_841585181 小时前
防破 · 稳定 · 易用——文心云网络验证,为您的软件商业化保驾护航
网络
星恒讯工业路由器2 小时前
公网IP、NAT、端口映射:外网访问家里的“通关攻略”
网络·智能路由器·信息与通信·nat·端口映射·公网ip
小蜗牛的路2 小时前
使用OpenSSL生成本地证书https+nginx
网络协议·nginx·https
前端炒粉2 小时前
个人简历面经总结二
前端·网络·vue.js·react.js·面试
碎碎念_4922 小时前
ACL包过滤、NAT技术、广域网协议
服务器·网络·安全·acl·nat
techdashen2 小时前
把正确性藏进类型里:从 Go 的 io.Reader 到 Rust 的 API 设计
网络·golang·rust
FPGA小迷弟3 小时前
vivado中的AXI Interconnect到底应该怎么用,他的底层原理是什么,一篇文档全部理清楚!!!
网络协议·tcp/ip·fpga开发·verilog·fpga
AI-好学者3 小时前
MCP企业运用全面知识点-基础篇
服务器·开发语言·网络·人工智能·python·架构
happyprince3 小时前
18-vLLM 结构化输出约束分析文档
网络·vllm