谷歌浏览器实施哪个版本的websockets协议草案 [英] Which version of websockets protocol draft does google chrome implement

查看:177
本文介绍了谷歌浏览器实施哪个版本的websockets协议草案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在java中实现一个websockets服务器,但我无法理解google chrome实现的websocket协议的版本。在这篇博客文章中,Chromium团队提到他们已经实现了websockets协议的版本76应该有以下握手请求(从正式版本76规范(1.2节)中复制):

  GET / demo HTTP / 1.1 
主机:example.com
连接:升级
Sec-WebSocket -Key2:12998 5 Y3 1.P00
Sec-WebSocket协议:示例
升级:WebSocket
Sec-WebSocket-Key1:4 @ 1 46546xW%0l 1 5
原产地:http://example.com

^ n:ds [4U

其中,我从google chrome(8.0.552.237)获得的握手请求是:

  GET / HTTP / 1.1 
升级:WebSocket
连接:升级
主机:localhost:8082
原产地:http :// localhost:8081
Sec-WebSocket-Key1:g3 I 9w F:Kt 3?u784C-0 99 5z
Sec-WebSocket -Key2:4 S5l& Y4m] 11 + 4 032s Ecfl

ïÁÁƒƒƒ^

有人可以向我解释为什么Google版本和官方规范之间存在差异。什么是谷歌版本的响应格式?



PS:有没有人估计什么时候websockets协议将被最终确定?

解决方案

Chrome目前实现 draft-hixie-thewebsocketprotocol-76 ,它也被称为草案,IETF-hybi-thewebsocketprotocol-03 。协议和规格现在由IETF HyBi工作组发布,因此03编号实际上更加正确,规范的下一个版本将继续编号(但大多数人仍称其为v76)。

您从Chrome-8.0.552获得的握手确实符合规范。区别在于,标题的排序可能会有所不同,并且每个新连接的键值都会有所不同,并且主机,源,路径和协议值取决于Javascript如何调用连接,还取决于调用的URL页面。

响应看起来像这样(尽管不完全是因为响应是基于客户端握手而产生的):

  HTTP / 1.1 101 WebSocket协议握手
升级:WebSocket
连接:升级
Sec-WebSocket-Origin:http://示例.com
Sec-WebSocket-位置:ws://example.com/demo
Sec-WebSocket协议:示例

8jKS'y:G * Co,Wxa-

我一直在关注HyBi工作组,并且没有估计协议何时最终确定。然而,新的草案(04)已经发布,试图解决浏览器厂商的安全问题。一个(05)版本可能会在未来几周内发布。浏览器供应商可能不会实施04(因为仍然存在较低共识的重要领域)。如果大多数浏览器厂商采用05,并且没有额外的安全问题,我怀疑该协议的最终版本不会有太大变化。



重要的是要注意但是,WebSockets的浏览器API可能不会受到协议更改的影响。


I am trying to implement a websockets server in java but I am having trouble understanding the version of websocket protocol does google chrome implements. In this blog post the Chromium team mentions that they have implemented version 76 of the websockets protocol which should have the following handshake request (copied from official version 76 spec (section 1.2)):

GET /demo HTTP/1.1
Host: example.com
Connection: Upgrade
Sec-WebSocket-Key2: 12998 5 Y3 1  .P00
Sec-WebSocket-Protocol: sample
Upgrade: WebSocket
Sec-WebSocket-Key1: 4 @1  46546xW%0l 1 5
Origin: http://example.com

^n:ds[4U

where as the handshake request I am getting from google chrome(8.0.552.237) is :

GET / HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8082
Origin: http://localhost:8081
Sec-WebSocket-Key1: g3 I 9w F :  Kt  3?u784C-0 99  5z
Sec-WebSocket-Key2: 4    S5l&Y4m]11+4 032s Ecfl

ïÿÁëƒ^

Can somebody please explain me why is there a discrepancy between googles version and the official spec. And what would be the right format of the response for google's version.

PS: does anybody has any estimate by when the websockets protocol would be finalized ?

解决方案

Chrome currently implements draft-hixie-thewebsocketprotocol-76 which is also known as draft-ietf-hybi-thewebsocketprotocol-03. The protocol and specs are now being published by the IETF HyBi working group thus the 03 numbering is actually more correct and the next versions of the spec will continue that numbering (but most people still call it v76).

The handshake you are getting from Chrome-8.0.552 does match the spec. The differences are because the ordering of the headers can vary and the keys will have different values for every new connection and the host, origin, path, and protocol values depend on how the Javascript invokes the connection and also depend on the URL of the invoking page.

The response will look something like this (although not exactly because the response is generated based on the client handshake):

HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: http://example.com
Sec-WebSocket-Location: ws://example.com/demo
Sec-WebSocket-Protocol: sample

8jKS'y:G*Co,Wxa-

I've been following the HyBi working group and there is no estimate for when the protocol will be finalized. However, a new draft (04) has already been published trying to address security concerns of the browser vendors. A (05) version will likely be published in the next few weeks. The browser vendors probably won't implement 04 (because there are still significant areas of low consensus). If most of the browser vendors adopt 05 and there are no additional security concerns I suspect that the final version of the protocol will not change much from there.

It's important to note however, that the browser API for WebSockets is likely not going to be affected by changes in the protocol.

这篇关于谷歌浏览器实施哪个版本的websockets协议草案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆