6 #include <boost/algorithm/string.hpp>
7 #include <boost/regex.hpp>
8 #include <openssl/bio.h>
9 #include <openssl/buffer.h>
10 #include <openssl/evp.h>
11 #include <openssl/hmac.h>
12 #include <openssl/sha.h>
18 "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
27 const HttpRequest& request, boost::shared_ptr<HttpConnection> connection,
28 const char* begin,
const char* end)
30 std::string connection_header =
32 std::string upgrade_header =
34 std::string websocket_key =
37 if (connection_header.find(
"Upgrade") != std::string::npos
38 && boost::iequals(upgrade_header,
"websocket")
39 && websocket_key.size() > 0)
44 unsigned char sha1_buf[20];
45 SHA1((
const unsigned char*)concat_key.data(), concat_key.size(),
49 BIO* b64 = BIO_new(BIO_f_base64());
50 BIO* bmem = BIO_new(BIO_s_mem());
51 b64 = BIO_push(b64, bmem);
52 BIO_write(b64, sha1_buf, 20);
55 BIO_get_mem_ptr(b64, &bptr);
56 std::string base64_key(bptr->data, bptr->length - 1);
61 .
header(
"Upgrade",
"websocket")
62 .
header(
"Connection",
"Upgrade")
63 .
header(
"Sec-WebSocket-Version",
"13")
64 .
header(
"Sec-WebSocket-Accept", base64_key)
70 handler_(request, websocket_connection);
71 websocket_connection->set_message_handler(message_handler);
72 websocket_connection->handle_read(begin, end);