Skip to content

Commit a495c8c

Browse files
author
Peter Thorson
committed
Merge branch 'develop' of https://github.com/zaphoyd/websocketpp into develop
2 parents fabf8bf + d3bec51 commit a495c8c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

websocketpp/processors/hybi00.hpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,29 @@ class hybi00 : public processor<config> {
186186

187187
/// Extracts requested subprotocols from a handshake request
188188
/**
189-
* hybi00 doesn't support subprotocols so there never will be any requested
189+
* hybi00 does support subprotocols
190+
* https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00#section-1.9
190191
*
191192
* @param [in] req The request to extract from
192193
* @param [out] subprotocol_list A reference to a vector of strings to store
193194
* the results in.
194195
*/
195-
lib::error_code extract_subprotocols(request_type const &,
196-
std::vector<std::string> &)
196+
lib::error_code extract_subprotocols(request_type const & req,
197+
std::vector<std::string> & subprotocol_list)
197198
{
199+
if (!req.get_header("Sec-WebSocket-Protocol").empty()) {
200+
http::parameter_list p;
201+
202+
if (!req.get_header_as_plist("Sec-WebSocket-Protocol",p)) {
203+
http::parameter_list::const_iterator it;
204+
205+
for (it = p.begin(); it != p.end(); ++it) {
206+
subprotocol_list.push_back(it->first);
207+
}
208+
} else {
209+
return error::make_error_code(error::subprotocol_parse_error);
210+
}
211+
}
198212
return lib::error_code();
199213
}
200214

websocketpp/uri.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@ class uri {
5454
int state = 0;
5555

5656
it = uri_string.begin();
57+
size_t uri_len = uri_string.length();
5758

58-
if (std::equal(it,it+6,"wss://")) {
59+
if (uri_len >= 7 && std::equal(it,it+6,"wss://")) {
5960
m_secure = true;
6061
m_scheme = "wss";
6162
it += 6;
62-
} else if (std::equal(it,it+5,"ws://")) {
63+
} else if (uri_len >= 6 && std::equal(it,it+5,"ws://")) {
6364
m_secure = false;
6465
m_scheme = "ws";
6566
it += 5;
66-
} else if (std::equal(it,it+7,"http://")) {
67+
} else if (uri_len >= 8 && std::equal(it,it+7,"http://")) {
6768
m_secure = false;
6869
m_scheme = "http";
6970
it += 7;
70-
} else if (std::equal(it,it+8,"https://")) {
71+
} else if (uri_len >= 9 && std::equal(it,it+8,"https://")) {
7172
m_secure = true;
7273
m_scheme = "https";
7374
it += 8;

0 commit comments

Comments
 (0)