Poco::Net::WebSocket: don't attempt to send empty credentials in response to 401 response

This commit is contained in:
Günter Obiltschnig 2019-06-24 20:17:49 +02:00
parent 8dc93706b3
commit 9f215cddce
2 changed files with 24 additions and 22 deletions

View File

@ -183,6 +183,8 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
return completeHandshake(cs, response, key);
}
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
{
if (!credentials.empty())
{
Poco::NullOutputStream null;
Poco::StreamCopier::copyStream(istr, null);
@ -203,6 +205,8 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
}
}
else throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
}
if (response.getStatus() == HTTPResponse::HTTP_OK)
{
throw WebSocketException("The server does not understand the WebSocket protocol", WS_ERR_NO_HANDSHAKE);

View File

@ -12,6 +12,7 @@
//
#define NOMINMAX
#include "Poco/Net/WebSocketImpl.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/WebSocket.h"
@ -25,9 +26,6 @@
#include <cstring>
#undef max
namespace Poco {
namespace Net {
@ -209,7 +207,7 @@ int WebSocketImpl::receiveBytes(void* buffer, int length, int)
if (payloadLength <= 0)
return payloadLength;
if (payloadLength > length)
throw WebSocketException(Poco::format("Insufficient buffer for payload size %hu", payloadLength), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
throw WebSocketException(Poco::format("Insufficient buffer for payload size %d", payloadLength), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
return receivePayload(reinterpret_cast<char*>(buffer), payloadLength, mask, useMask);
}
@ -247,7 +245,7 @@ int WebSocketImpl::receiveNBytes(void* buffer, int bytes)
int WebSocketImpl::receiveSomeBytes(char* buffer, int bytes)
{
int n = _buffer.size() - _bufferOffset;
int n = static_cast<int>(_buffer.size()) - _bufferOffset;
if (n > 0)
{
if (bytes < n) n = bytes;
@ -391,7 +389,7 @@ Poco::Timespan WebSocketImpl::getReceiveTimeout()
int WebSocketImpl::available()
{
int n = _buffer.size() - _bufferOffset;
int n = static_cast<int>(_buffer.size()) - _bufferOffset;
if (n > 0)
return n + _pStreamSocketImpl->available();
else