|
7 | 7 |
|
8 | 8 | #include "wampcc/websocket_protocol.h" |
9 | 9 |
|
| 10 | +#include "wampcc/platform.h" |
10 | 11 | #include "wampcc/utils.h" |
11 | 12 | #include "wampcc/tcp_socket.h" |
12 | 13 | #include "wampcc/http_parser.h" |
@@ -65,14 +66,17 @@ inline std::string make_accept_key(const std::string& challenge) |
65 | 66 | } |
66 | 67 |
|
67 | 68 |
|
68 | | -static bool string_list_contains(const std::string & source, |
69 | | - const std::string & match) |
| 69 | +/* Test whether a HTTP header contains a desired value. Note that when checking |
| 70 | + * request and response headers, we are generally case |
| 71 | + * insensitive. I.e. according to RFC2616, all header field names in both HTTP |
| 72 | + * requests and HTTP responses are case-insensitive. */ |
| 73 | +static bool header_contains(const std::string & source, |
| 74 | + const std::string & match) |
70 | 75 | { |
71 | | - |
72 | 76 | for (auto & i : tokenize(source.c_str(), ',', true)) |
73 | 77 | { |
74 | 78 | std::string trimmed = trim(i); |
75 | | - if (trimmed == match) |
| 79 | + if (strcasecmp(trimmed.c_str(), match.c_str())==0) |
76 | 80 | return true; |
77 | 81 | } |
78 | 82 | return false; |
@@ -226,9 +230,9 @@ void websocket_protocol::io_on_read(char* src, size_t len) |
226 | 230 | { |
227 | 231 | if ( m_http_parser->is_upgrade() && |
228 | 232 | m_http_parser->has("Upgrade") && |
229 | | - string_list_contains(m_http_parser->get("Upgrade"), "websocket") && |
| 233 | + header_contains(m_http_parser->get("Upgrade"), "websocket") && |
230 | 234 | m_http_parser->has("Connection") && |
231 | | - string_list_contains(m_http_parser->get("Connection"), "Upgrade") && |
| 235 | + header_contains(m_http_parser->get("Connection"), "Upgrade") && |
232 | 236 | m_http_parser->has("Sec-WebSocket-Key") && |
233 | 237 | m_http_parser->has("Sec-WebSocket-Version") ) |
234 | 238 | { |
@@ -353,9 +357,9 @@ void websocket_protocol::io_on_read(char* src, size_t len) |
353 | 357 | { |
354 | 358 | if ( m_http_parser->is_upgrade() && |
355 | 359 | m_http_parser->has("Upgrade") && |
356 | | - string_list_contains(m_http_parser->get("Upgrade"), "websocket") && |
| 360 | + header_contains(m_http_parser->get("Upgrade"), "websocket") && |
357 | 361 | m_http_parser->has("Connection") && |
358 | | - string_list_contains(m_http_parser->get("Connection"), "Upgrade") && |
| 362 | + header_contains(m_http_parser->get("Connection"), "Upgrade") && |
359 | 363 | m_http_parser->has("Sec-WebSocket-Accept") && |
360 | 364 | m_http_parser->http_status_phrase() == "Switching Protocols" && |
361 | 365 | m_http_parser->http_status_code() == http_parser::status_code_switching_protocols) |
|
0 commit comments