diff --git a/examples/echo_server/echo_server b/examples/echo_server/echo_server index 3abbfec5f5..0b341d7092 100755 Binary files a/examples/echo_server/echo_server and b/examples/echo_server/echo_server differ diff --git a/readme.txt b/readme.txt index 919bef6659..8570367bc7 100644 --- a/readme.txt +++ b/readme.txt @@ -72,7 +72,6 @@ Build tested on Outstanding issues - Acknowledgement details -- Add license information to each file - Subprotocol negotiation interface - check draft 14 issues - session.cpp - add_header. Decide what should happen with multiple calls to diff --git a/src/websocket_session.cpp b/src/websocket_session.cpp index e16c183e9a..5ccc1e1a4b 100644 --- a/src/websocket_session.cpp +++ b/src/websocket_session.cpp @@ -83,6 +83,13 @@ void session::remove_host(std::string host) { m_hosts.erase(host); } +void session::set_max_message_size(uint64_t val) { + if (val > frame::PAYLOAD_64BIT_LIMIT) { + throw "illegal maximum message size"; + } + m_max_message_size = val; +} + std::string session::get_header(const std::string& key) const { std::map::const_iterator h = m_headers.find(key); @@ -289,10 +296,15 @@ void session::handle_read_handshake(const boost::system::error_code& e, this->set_http_error(400); } - if (get_header("Sec-WebSocket-Version") != "8" && - get_header("Sec-WebSocket-Version") != "7") { - std::cerr << "Invalid or missing Sec-Websocket-Version header." << std::endl; + if (get_header("Sec-WebSocket-Version") == "" ) { + std::cerr << "Missing Sec-Websocket-Version header." << std::endl; this->set_http_error(400); + } else { + m_version = strtoul(get_header("Sec-WebSocket-Version").c_str(),NULL,10); + + if (m_version != 7 && m_version != 8 && m_version != 13) { + this->set_http_error(400); + } } if (m_http_error_code != 0) { diff --git a/src/websocket_session.hpp b/src/websocket_session.hpp index 79b871b6c7..750e726c34 100644 --- a/src/websocket_session.hpp +++ b/src/websocket_session.hpp @@ -99,6 +99,10 @@ public: void add_host(std::string host); void remove_host(std::string host); + // Sets the maximum allowed message size. Higher values will require larger + // memory buffers. Maximum value is 2^63, default value is ?? + void set_max_message_size(uint64_t); + // By default a failed handshake validation will return an HTTP 400 Bad // Request error. If your application wants to reject the connection for // another reason it can be set here. Example: 404 if the resource request @@ -199,28 +203,37 @@ private: std::string lookup_http_error_string(int code); private: - std::set m_hosts; - std::string m_host; - tcp::socket m_socket; - status_code m_status; - int m_http_error_code; - std::string m_http_error_string; + // Connection specific constants (defaults to values from server, can be + // changed on a per connection basis if needed.) + std::set m_hosts; + uint64_t m_max_message_size; + // Immutable state about the current connection from the handshake + std::string m_request; + std::map m_headers; + unsigned int m_version; + std::string m_subprotocol; + + // Mutable connection state; + status_code m_status; + + // Connection Resources + tcp::socket m_socket; + connection_handler_ptr m_local_interface; + + // Buffers boost::asio::streambuf m_buf; + + // unorganized + int m_http_error_code; + std::string m_http_error_string; std::string m_handshake; - - std::string m_request; - std::map m_headers; - frame m_read_frame; frame m_write_frame; std::vector m_current_message; - bool m_error; bool m_fragmented; frame::opcode m_current_opcode; - - connection_handler_ptr m_local_interface; }; }