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

相关推荐
Hello_Embed17 分钟前
USB 学习指南+软硬件框架
网络·笔记·stm32·嵌入式·ai编程
网络与设备以及操作系统学习使用者31 分钟前
ARP报文保护触发与解决详解
运维·网络·学习·华为
humors22133 分钟前
检查网址连通性的python脚本
网络·python·网站·检测网址·查询网址·网址连通性·网址可访问性
今天也是元气满满的一天呢1 小时前
详解SQL注入问题
网络·数据库·sql
liulilittle1 小时前
TCP UCP v1.0:当 BBRv1 遇上卡尔曼滤波
网络·网络协议·tcp/ip
哈撒Ki2 小时前
快速入门WebSocket
前端·websocket
一路往蓝-Anbo2 小时前
第四章:手撕协议栈 —— 缓冲区与结构体数据的 Mock 技巧
网络·stm32·单片机·嵌入式硬件·软件工程·tdd
号码认证服务2 小时前
小米、OPPO、VIVO手机支持号码认证显示公司名吗?
java·服务器·网络·经验分享·智能手机·云计算·php
小娄~~2 小时前
TCP/IP协议和TFTP协议
网络·网络协议·tcp/ip
Rudon滨海渔村2 小时前
macOS启动转换助理出现“不能下载该软件,因为网络出现问题 ”
网络·macos