aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2016-09-15 17:29:08 +0900
committeripknHama <ipknhama@gmail.com>2016-09-15 17:29:08 +0900
commit7af78aff5ac1f0a76d3aa62f08e642558d8e58fc (patch)
tree789aedef309da4c69fe1998355eae2648b5e5af3 /include
parent806ef51092fd94c0788d5b4821331353c3ee127a (diff)
downloadcrow-7af78aff5ac1f0a76d3aa62f08e642558d8e58fc.tar.gz
crow-7af78aff5ac1f0a76d3aa62f08e642558d8e58fc.zip
Fix bugs in websocket
- `Upgrade: websocket` should be case-insensitive - Using network byte order for length field
Diffstat (limited to 'include')
-rw-r--r--include/websocket.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/include/websocket.h b/include/websocket.h
index 2873e45..5b82046 100644
--- a/include/websocket.h
+++ b/include/websocket.h
@@ -1,4 +1,5 @@
#pragma once
+#include <boost/algorithm/string/predicate.hpp>
#include "socket_adaptors.h"
#include "http_request.h"
#include "TinySHA1.hpp"
@@ -41,7 +42,7 @@ namespace crow
std::function<void(crow::websocket::connection&)> error_handler)
: adaptor_(std::move(adaptor)), open_handler_(std::move(open_handler)), message_handler_(std::move(message_handler)), close_handler_(std::move(close_handler)), error_handler_(std::move(error_handler))
{
- if (req.get_header_value("upgrade") != "websocket")
+ if (!boost::iequals(req.get_header_value("upgrade"), "websocket"))
{
adaptor.close();
delete this;
@@ -131,13 +132,13 @@ namespace crow
else if (size < 0x10000)
{
buf[1] += 126;
- *(uint16_t*)(buf+2) = (uint16_t)size;
+ *(uint16_t*)(buf+2) = htons((uint16_t)size);
return {buf, buf+4};
}
else
{
buf[1] += 127;
- *(uint64_t*)(buf+2) = (uint64_t)size;
+ *(uint64_t*)(buf+2) = ((1==htonl(1)) ? (uint64_t)size : ((uint64_t)htonl((size) & 0xFFFFFFFF) << 32) | htonl((size) >> 32));
return {buf, buf+10};
}
}