客戶端必須在它發送到服務器的全部幀中添加掩碼(Mask)

 


在WebSocket協議中,數據是經過一系列數據幀來進行傳輸的。爲了不因爲網絡中介(例如一些攔截代理)或者一些在第10.3節討論的安全緣由,客戶端必須在它發送到服務器的全部幀中添加掩碼(Mask)(具體細節見5.3節)。(注意:不管WebSocket協議是否使用了TLS,幀都須要添加掩碼)。服務端收到沒有添加掩碼的數據幀之後,必須當即關閉鏈接。在這種狀況下,服務端能夠發送一個在7.4.1節定義的狀態碼爲1002(協議錯誤)的關閉幀。服務端禁止在發送數據幀給客戶端時添加掩碼。客戶端若是收到了一個添加了掩碼的幀,必須當即關閉鏈接。在這種狀況下,它可使用第7.4.1節定義的1002(協議錯誤)狀態碼。(這些規則可能會在未來的規範中放開)。

基礎的數據幀協議使用操做碼、有效負載長度和在「有效負載數據」中定義的放置「擴展數據」與「引用數據」的指定位置來定義幀類型。特定的bit位和操做碼爲未來的協議擴展作了保留。

一個數據幀能夠在開始握手完成以後和終端發送了一個關閉幀以前的任意一個時間經過客戶端或者服務端進行傳輸(第5.5.1節)。
 
 

5. Data Framing

5.1. Overview

 In the WebSocket Protocol, data is transmitted using a sequence of frames. To avoid confusing network intermediaries (such as intercepting proxies) and for security reasons that are further discussed in Section 10.3, a client MUST mask all frames that it sends to the server (see Section 5.3 for further details). (Note that masking is done whether or not the WebSocket Protocol is running over TLS.) The server MUST close the connection upon receiving a frame that is not masked. In this case, a server MAY send a Close frame with a status code of 1002 (protocol error) as defined in Section 7.4.1. A server MUST NOT mask any frames that it sends to the client. A client MUST close a connection if it detects a masked frame. In this case, it MAY use the status code 1002 (protocol error) as defined in Section 7.4.1. (These rules might be relaxed in a future specification.) The base framing protocol defines a frame type with an opcode, a payload length, and designated locations for "Extension data" and "Application data", which together define the "Payload data". Certain bits and opcodes are reserved for future expansion of the protocol. Fette & Melnikov Standards Track [Page 27]


RFC 6455                 The WebSocket Protocol            December 2011


   A data frame MAY be transmitted by either the client or the server at
   any time after opening handshake completion and before that endpoint
   has sent a Close frame (Section 5.5.1).

 

RFC 6455 - The WebSocket Protocol https://tools.ietf.org/html/rfc6455#section-5.1html

相關文章
相關標籤/搜索