1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_DRAFT75_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_DRAFT75_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "googleurl/src/gurl.h" 13 #include "net/websockets/websocket_handshake.h" 14 15 namespace net { 16 17 class HttpResponseHeaders; 18 19 class WebSocketHandshakeDraft75 : public WebSocketHandshake { 20 public: 21 static const int kWebSocketPort; 22 static const int kSecureWebSocketPort; 23 static const char kServerHandshakeHeader[]; 24 static const size_t kServerHandshakeHeaderLength; 25 static const char kUpgradeHeader[]; 26 static const size_t kUpgradeHeaderLength; 27 static const char kConnectionHeader[]; 28 static const size_t kConnectionHeaderLength; 29 30 WebSocketHandshakeDraft75(const GURL& url, 31 const std::string& origin, 32 const std::string& location, 33 const std::string& protocol); 34 virtual ~WebSocketHandshakeDraft75(); 35 36 // Creates the client handshake message from |this|. 37 virtual std::string CreateClientHandshakeMessage(); 38 39 // Reads server handshake message in |len| of |data|, updates |mode_| and 40 // returns number of bytes of the server handshake message. 41 // Once connection is established, |mode_| will be MODE_CONNECTED. 42 // If connection establishment failed, |mode_| will be MODE_FAILED. 43 // Returns negative if the server handshake message is incomplete. 44 virtual int ReadServerHandshake(const char* data, size_t len); 45 46 private: 47 // Processes server handshake message, parsed as |headers|, and updates 48 // |ws_origin_|, |ws_location_| and |ws_protocol_|. 49 // Returns true if it's ok. 50 // Returns false otherwise (e.g. duplicate WebSocket-Origin: header, etc.) 51 virtual bool ProcessHeaders(const HttpResponseHeaders& headers); 52 53 // Checks |ws_origin_|, |ws_location_| and |ws_protocol_| are valid 54 // against |origin_|, |location_| and |protocol_|. 55 // Returns true if it's ok. 56 // Returns false otherwise (e.g. origin mismatch, etc.) 57 virtual bool CheckResponseHeaders() const; 58 59 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeDraft75); 60 }; 61 62 } // namespace net 63 64 #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_DRAFT75_H_ 65