Skip to content

Commit 6d61386

Browse files
committed
GH110: WebSocket accept() fails when Connection header contains multiple tokens
fixed GH pocoproject#110: WebSocket accept() fails when Connection header contains multiple tokens
1 parent 4cb8b78 commit 6d61386

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎CHANGELOG‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Release 1.5.2 (2013-03-??)
1212
- merged GH #91: Improve SQLite multi-threaded use (by Rangel Reale)
1313
- merged GH #86: Invalid pointers to vector internals (by Adrian Imboden)
1414
- automatic library initialization macros
15+
- fixed GH #110: WebSocket accept() fails when Connection header contains multiple tokens
1516

1617
Release 1.5.1 (2013-01-11)
1718
==========================

‎Net/src/WebSocket.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "Poco/SHA1Engine.h"
4848
#include "Poco/Base64Encoder.h"
4949
#include "Poco/String.h"
50+
#include "Poco/StringTokenizer.h"
5051
#include "Poco/Random.h"
5152
#include "Poco/StreamCopier.h"
5253
#include <sstream>
@@ -133,8 +134,8 @@ WebSocket::Mode WebSocket::mode() const
133134

134135
WebSocketImpl* WebSocket::accept(HTTPServerRequest& request, HTTPServerResponse& response)
135136
{
136-
if (icompare(request.get("Connection", ""), "Upgrade") == 0 &&
137-
icompare(request.get("Upgrade", ""), "websocket") == 0)
137+
StringTokenizer st(request.get("Connection", ""), ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
138+
if (st.has("Upgrade") && icompare(request.get("Upgrade", ""), "websocket") == 0)
138139
{
139140
std::string version = request.get("Sec-WebSocket-Version", "");
140141
if (version.empty()) throw WebSocketException("Missing Sec-WebSocket-Version in handshake request", WS_ERR_HANDSHAKE_NO_VERSION);

‎Net/testsuite/src/TCPServerTest.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ void TCPServerTest::testMultiConnections()
251251
ss5.close();
252252
ss6.close();
253253
Thread::sleep(300);
254-
assert (srv.currentConnections() == 0);}
254+
assert (srv.currentConnections() == 0);
255+
}
255256

256257

257258
void TCPServerTest::setUp()

0 commit comments

Comments
 (0)