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

相关推荐
怀旧,19 小时前
【Linux网络编程】2. Socket编程 UDP
linux·网络·udp
liulilittle19 小时前
TCP UCP v1.0:BBR 的非破坏性约束层
网络·c++·网络协议·tcp/ip·算法·c·通信
HelloWorld工程师19 小时前
SSL证书在哪里可以免费且快速申请?
服务器·网络协议·ssl
皮皮学姐分享-ppx20 小时前
上市公司数字技术风险暴露数据(2010-2024)|《经济研究》同款大模型测算
大数据·网络·数据库·人工智能·chatgpt·制造
皮卡蛋炒饭.21 小时前
应用层协议HTTP
网络·网络协议·http
wearegogog12321 小时前
Modbus TCP 通讯协议实现
服务器·网络·tcp/ip
怀旧,21 小时前
【Linux网络编程】1. 网络基础概念
linux·网络
怀旧,1 天前
【Linux网络编程】5. 应用层协议 HTTP
linux·网络·http
志栋智能1 天前
超自动化巡检:量化运维成效的标尺
运维·网络·人工智能·自动化
夏日听雨眠1 天前
Linux(信号,管道,共享内存)
java·服务器·网络