mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-29 21:22:11 +01:00
Poco::Net::WebSocket: don't attempt to send empty credentials in response to 401 response
This commit is contained in:
parent
8dc93706b3
commit
9f215cddce
@ -184,24 +184,28 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
|
||||
}
|
||||
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
|
||||
{
|
||||
Poco::NullOutputStream null;
|
||||
Poco::StreamCopier::copyStream(istr, null);
|
||||
credentials.authenticate(request, response);
|
||||
if (!cs.getProxyHost().empty() && !cs.secure())
|
||||
if (!credentials.empty())
|
||||
{
|
||||
cs.reset();
|
||||
cs.proxyTunnel();
|
||||
}
|
||||
cs.sendRequest(request);
|
||||
cs.receiveResponse(response);
|
||||
if (response.getStatus() == HTTPResponse::HTTP_SWITCHING_PROTOCOLS)
|
||||
{
|
||||
return completeHandshake(cs, response, key);
|
||||
}
|
||||
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
|
||||
{
|
||||
throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
|
||||
Poco::NullOutputStream null;
|
||||
Poco::StreamCopier::copyStream(istr, null);
|
||||
credentials.authenticate(request, response);
|
||||
if (!cs.getProxyHost().empty() && !cs.secure())
|
||||
{
|
||||
cs.reset();
|
||||
cs.proxyTunnel();
|
||||
}
|
||||
cs.sendRequest(request);
|
||||
cs.receiveResponse(response);
|
||||
if (response.getStatus() == HTTPResponse::HTTP_SWITCHING_PROTOCOLS)
|
||||
{
|
||||
return completeHandshake(cs, response, key);
|
||||
}
|
||||
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
|
||||
{
|
||||
throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
else throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
|
||||
}
|
||||
if (response.getStatus() == HTTPResponse::HTTP_OK)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user