Index: net/websockets/websocket_handshake_handler.h |
diff --git a/net/websockets/websocket_handshake_handler.h b/net/websockets/websocket_handshake_handler.h |
index 855d12f349daeebc7b98cefadb77a2f77145cade..b0d34a2bedbf22a0433c593926151f478531123a 100644 |
--- a/net/websockets/websocket_handshake_handler.h |
+++ b/net/websockets/websocket_handshake_handler.h |
@@ -9,6 +9,21 @@ |
// - We don't trust WebKit renderer process, so we'll not expose HttpOnly |
// cookies to the renderer process, so handles HttpOnly cookies in |
// browser process. |
+// |
+// The classes below support two styles of handshake: handshake based |
+// on hixie-76 draft and one based on hybi-04 draft. The critical difference |
+// between these two is how they pass challenge and response values. Hixie-76 |
+// based handshake appends a few bytes of binary data after header fields of |
+// handshake request and response. These data are called "key3" (for request) |
+// or "response key" (for response). On the other hand, handshake based on |
+// hybi-04 and later drafts put challenge and response values into handshake |
+// header fields, thus we do not need to send or receive extra bytes after |
+// handshake headers. |
+// |
+// While we are working on updating WebSocket implementation in WebKit to |
+// conform to the latest procotol draft, we need to accept both styles of |
+// handshake. After we land the protocol changes in WebKit, we will be able to |
+// drop codes handling old-style handshake. |
#ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_HANDLER_H_ |
#define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_HANDLER_H_ |
@@ -45,10 +60,12 @@ class WebSocketHandshakeRequestHandler { |
size_t headers_to_remove_len); |
// Gets request info to open WebSocket connection. |
- // Also, fill challange data in |challenge|. |
+ // Fills challange data (concatenation of key1, 2 and 3 for hybi-03 and |
+ // earlier, or Sec-WebSocket-Key header value for hybi-04 and later) |
+ // in |challenge|. |
HttpRequestInfo GetRequestInfo(const GURL& url, std::string* challenge); |
// Gets request as SpdyHeaderBlock. |
- // Also, fill challenge data in |challenge|. |
+ // Also, fills challenge data in |challenge|. |
bool GetRequestHeaderBlock(const GURL& url, |
spdy::SpdyHeaderBlock* headers, |
std::string* challenge); |
@@ -58,12 +75,18 @@ class WebSocketHandshakeRequestHandler { |
// Calling raw_length is valid only after GetRawRquest() call. |
size_t raw_length() const; |
+ // True if the parsed handshake conforms to hybi-04 or later, which means |
+ // it has Sec-WebSocket-Key header and does not have "key3" part after |
+ // the handshake headers. |
+ bool is_hybi04_handshake() const; |
ukai
2011/04/13 04:09:00
maybe, HasSecWebSocketKey() or HasKey3Data() ?
or
Yuta Kitamura
2011/04/13 11:23:50
Used Sec-WebSocket-Version. Done.
|
+ |
private: |
std::string status_line_; |
std::string headers_; |
std::string key3_; |
int original_length_; |
int raw_length_; |
+ bool is_hybi04_handshake_; |
DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeRequestHandler); |
}; |
@@ -73,6 +96,11 @@ class WebSocketHandshakeResponseHandler { |
WebSocketHandshakeResponseHandler(); |
~WebSocketHandshakeResponseHandler(); |
+ // Set true if the format of handshake request was hybi-04 or newer |
+ // before parsing the response. Default is false. |
+ bool expect_hybi04_handshake() const; |
+ void set_expect_hybi04_handshake(bool expect_hybi04_handshake); |
+ |
// Parses WebSocket handshake response from WebSocket server. |
// Returns number of bytes in |data| used for WebSocket handshake response |
// message, including response key. If it already got whole WebSocket |
@@ -105,12 +133,17 @@ class WebSocketHandshakeResponseHandler { |
std::string GetResponse(); |
private: |
+ // Returns the length of response key. This function will return 0 |
+ // if |expect_hybi04_handshake_| is set to true. |
+ size_t GetResponseKeySize() const; |
+ |
std::string original_; |
int original_header_length_; |
std::string status_line_; |
std::string headers_; |
std::string header_separator_; |
std::string key_; |
+ bool expect_hybi04_handshake_; |
DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeResponseHandler); |
}; |