void HTTPSClientSession::connect(const SocketAddress& address) { if (getProxyHost().empty() || bypassProxy()) { SecureStreamSocket sss(socket()); if (sss.getPeerHostName().empty()) { sss.setPeerHostName(getHost()); } if (_pContext->sessionCacheEnabled()) { sss.useSession(_pSession); } HTTPSession::connect(address); if (_pContext->sessionCacheEnabled()) { _pSession = sss.currentSession(); } } else { StreamSocket proxySocket(proxyConnect()); SecureStreamSocket secureSocket = SecureStreamSocket::attach(proxySocket, getHost(), _pContext, _pSession); attachSocket(secureSocket); if (_pContext->sessionCacheEnabled()) { _pSession = secureSocket.currentSession(); } } }
void HTTPSClientSession::connect(const SocketAddress& address) { if (getProxyHost().empty()) { SecureStreamSocket sss(socket()); if (_pContext->sessionCacheEnabled()) { sss.useSession(_pSession); } HTTPSession::connect(address); if (_pContext->sessionCacheEnabled()) { _pSession = sss.currentSession(); } } else { HTTPClientSession proxySession(address); proxySession.setHost(getProxyHost()); proxySession.setPort(getProxyPort()); proxySession.setTimeout(getTimeout()); SocketAddress targetAddress(getHost(), getPort()); HTTPRequest proxyRequest(HTTPRequest::HTTP_CONNECT, targetAddress.toString(), HTTPMessage::HTTP_1_1); HTTPResponse proxyResponse; proxyRequest.set("Proxy-Connection", "keep-alive"); proxyRequest.set("Host", getHost()); proxyAuthenticateImpl(proxyRequest); proxySession.setKeepAlive(true); proxySession.sendRequest(proxyRequest); proxySession.receiveResponse(proxyResponse); if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK) throw HTTPException("Cannot establish proxy connection", proxyResponse.getReason()); StreamSocket proxySocket(proxySession.detachSocket()); SecureStreamSocket secureSocket = SecureStreamSocket::attach(proxySocket, getHost(), _pContext, _pSession); attachSocket(secureSocket); if (_pContext->sessionCacheEnabled()) { _pSession = secureSocket.currentSession(); } } }