mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 01:16:55 +02: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)
|
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
|
||||||
{
|
{
|
||||||
Poco::NullOutputStream null;
|
if (!credentials.empty())
|
||||||
Poco::StreamCopier::copyStream(istr, null);
|
|
||||||
credentials.authenticate(request, response);
|
|
||||||
if (!cs.getProxyHost().empty() && !cs.secure())
|
|
||||||
{
|
{
|
||||||
cs.reset();
|
Poco::NullOutputStream null;
|
||||||
cs.proxyTunnel();
|
Poco::StreamCopier::copyStream(istr, null);
|
||||||
}
|
credentials.authenticate(request, response);
|
||||||
cs.sendRequest(request);
|
if (!cs.getProxyHost().empty() && !cs.secure())
|
||||||
cs.receiveResponse(response);
|
{
|
||||||
if (response.getStatus() == HTTPResponse::HTTP_SWITCHING_PROTOCOLS)
|
cs.reset();
|
||||||
{
|
cs.proxyTunnel();
|
||||||
return completeHandshake(cs, response, key);
|
}
|
||||||
}
|
cs.sendRequest(request);
|
||||||
else if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED)
|
cs.receiveResponse(response);
|
||||||
{
|
if (response.getStatus() == HTTPResponse::HTTP_SWITCHING_PROTOCOLS)
|
||||||
throw WebSocketException("Not authorized", WS_ERR_UNAUTHORIZED);
|
{
|
||||||
|
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)
|
if (response.getStatus() == HTTPResponse::HTTP_OK)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#define NOMINMAX
|
||||||
#include "Poco/Net/WebSocketImpl.h"
|
#include "Poco/Net/WebSocketImpl.h"
|
||||||
#include "Poco/Net/NetException.h"
|
#include "Poco/Net/NetException.h"
|
||||||
#include "Poco/Net/WebSocket.h"
|
#include "Poco/Net/WebSocket.h"
|
||||||
@ -25,9 +26,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
#undef max
|
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
@ -209,7 +207,7 @@ int WebSocketImpl::receiveBytes(void* buffer, int length, int)
|
|||||||
if (payloadLength <= 0)
|
if (payloadLength <= 0)
|
||||||
return payloadLength;
|
return payloadLength;
|
||||||
if (payloadLength > length)
|
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);
|
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 WebSocketImpl::receiveSomeBytes(char* buffer, int bytes)
|
||||||
{
|
{
|
||||||
int n = _buffer.size() - _bufferOffset;
|
int n = static_cast<int>(_buffer.size()) - _bufferOffset;
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
{
|
{
|
||||||
if (bytes < n) n = bytes;
|
if (bytes < n) n = bytes;
|
||||||
@ -391,7 +389,7 @@ Poco::Timespan WebSocketImpl::getReceiveTimeout()
|
|||||||
|
|
||||||
int WebSocketImpl::available()
|
int WebSocketImpl::available()
|
||||||
{
|
{
|
||||||
int n = _buffer.size() - _bufferOffset;
|
int n = static_cast<int>(_buffer.size()) - _bufferOffset;
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
return n + _pStreamSocketImpl->available();
|
return n + _pStreamSocketImpl->available();
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user