diff options
author | eidheim <eidheim@gmail.com> | 2018-11-08 10:27:02 +0300 |
---|---|---|
committer | eidheim <eidheim@gmail.com> | 2018-11-08 10:27:12 +0300 |
commit | 5ebcb3889ad08ac12f308c0dd5f1c9f31f8f85a1 (patch) | |
tree | 1ba096265ab630fca6fb9f0ed38d8e9a082ed05c /server_ws.hpp | |
parent | b7972accbc1e3ee6f9b501cf7d9da7d80765bad8 (diff) |
Fixes #106: Added Config.header to server that can be used to send additional header fields to client
Diffstat (limited to 'server_ws.hpp')
-rw-r--r-- | server_ws.hpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/server_ws.hpp b/server_ws.hpp index 4fd0432..e2fae0a 100644 --- a/server_ws.hpp +++ b/server_ws.hpp @@ -186,7 +186,7 @@ namespace SimpleWeb { } } - bool generate_handshake(const std::shared_ptr<asio::streambuf> &write_buffer) { + bool generate_handshake(const std::shared_ptr<asio::streambuf> &write_buffer, const CaseInsensitiveMultimap &additional_header_fields) { std::ostream handshake(write_buffer.get()); auto header_it = header.find("Sec-WebSocket-Key"); @@ -200,6 +200,8 @@ namespace SimpleWeb { handshake << "Upgrade: websocket\r\n"; handshake << "Connection: Upgrade\r\n"; handshake << "Sec-WebSocket-Accept: " << Crypto::Base64::encode(sha1) << "\r\n"; + for(auto &header_field : additional_header_fields) + handshake << header_field.first << ": " << header_field.second << "\r\n"; handshake << "\r\n"; return true; @@ -377,6 +379,8 @@ namespace SimpleWeb { /// Maximum size of incoming messages. Defaults to architecture maximum. /// Exceeding this limit will result in a message_size error code and the connection will be closed. std::size_t max_message_size = std::numeric_limits<std::size_t>::max(); + /// Additional header fields to send when performing WebSocket handshake. + CaseInsensitiveMultimap header; /// IPv4 address in dotted decimal form or IPv6 address in hexadecimal notation. /// If empty, the address will be any address. std::string address; @@ -563,7 +567,7 @@ namespace SimpleWeb { if(regex::regex_match(connection->path, path_match, regex_endpoint.first)) { auto write_buffer = std::make_shared<asio::streambuf>(); - if(connection->generate_handshake(write_buffer)) { + if(connection->generate_handshake(write_buffer, config.header)) { connection->path_match = std::move(path_match); connection->set_timeout(config.timeout_request); asio::async_write(*connection->socket, *write_buffer, [this, connection, write_buffer, ®ex_endpoint](const error_code &ec, std::size_t /*bytes_transferred*/) { |