diff --git a/Net/src/WebSocket.cpp b/Net/src/WebSocket.cpp index d25b00ae2..17816ad00 100644 --- a/Net/src/WebSocket.cpp +++ b/Net/src/WebSocket.cpp @@ -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) { diff --git a/Net/src/WebSocketImpl.cpp b/Net/src/WebSocketImpl.cpp index ec62106c1..7c97fa7b0 100644 --- a/Net/src/WebSocketImpl.cpp +++ b/Net/src/WebSocketImpl.cpp @@ -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 -#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(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(_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(_buffer.size()) - _bufferOffset; if (n > 0) return n + _pStreamSocketImpl->available(); else