summaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp')
-rw-r--r--contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp b/contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
new file mode 100644
index 00000000000..325f36a60a6
--- /dev/null
+++ b/contrib/libs/poco/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
@@ -0,0 +1,189 @@
+//
+// HTTPSClientSession.cpp
+//
+// Library: NetSSL_OpenSSL
+// Package: HTTPSClient
+// Module: HTTPSClientSession
+//
+// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SecureStreamSocketImpl.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Net/SSLException.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/NumberFormatter.h"
+
+
+using Poco::NumberFormatter;
+using Poco::IllegalStateException;
+
+
+namespace Poco {
+namespace Net {
+
+
+HTTPSClientSession::HTTPSClientSession():
+ HTTPClientSession(SecureStreamSocket()),
+ _pContext(SSLManager::instance().defaultClientContext())
+{
+ setPort(HTTPS_PORT);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& socket):
+ HTTPClientSession(socket),
+ _pContext(socket.context())
+{
+ setPort(HTTPS_PORT);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& socket, Session::Ptr pSession):
+ HTTPClientSession(socket),
+ _pContext(socket.context()),
+ _pSession(pSession)
+{
+ setPort(HTTPS_PORT);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const std::string& host, Poco::UInt16 port):
+ HTTPClientSession(SecureStreamSocket()),
+ _pContext(SSLManager::instance().defaultClientContext())
+{
+ setHost(host);
+ setPort(port);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(Context::Ptr pContext):
+ HTTPClientSession(SecureStreamSocket(pContext)),
+ _pContext(pContext)
+{
+}
+
+
+HTTPSClientSession::HTTPSClientSession(Context::Ptr pContext, Session::Ptr pSession):
+ HTTPClientSession(SecureStreamSocket(pContext, pSession)),
+ _pContext(pContext),
+ _pSession(pSession)
+{
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const std::string& host, Poco::UInt16 port, Context::Ptr pContext):
+ HTTPClientSession(SecureStreamSocket(pContext)),
+ _pContext(pContext)
+{
+ setHost(host);
+ setPort(port);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const std::string& host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession):
+ HTTPClientSession(SecureStreamSocket(pContext, pSession)),
+ _pContext(pContext),
+ _pSession(pSession)
+{
+ setHost(host);
+ setPort(port);
+}
+
+
+HTTPSClientSession::~HTTPSClientSession()
+{
+}
+
+
+bool HTTPSClientSession::secure() const
+{
+ return true;
+}
+
+
+void HTTPSClientSession::abort()
+{
+ SecureStreamSocket sss(socket());
+ sss.abort();
+}
+
+
+X509Certificate HTTPSClientSession::serverCertificate()
+{
+ SecureStreamSocket sss(socket());
+ return sss.peerCertificate();
+}
+
+
+std::string HTTPSClientSession::proxyRequestPrefix() const
+{
+ return std::string();
+}
+
+
+void HTTPSClientSession::proxyAuthenticate(HTTPRequest& request)
+{
+}
+
+
+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();
+ }
+ }
+}
+
+
+int HTTPSClientSession::read(char* buffer, std::streamsize length)
+{
+ try
+ {
+ return HTTPSession::read(buffer, length);
+ }
+ catch(SSLConnectionUnexpectedlyClosedException&)
+ {
+ return 0;
+ }
+}
+
+
+Session::Ptr HTTPSClientSession::sslSession()
+{
+ return _pSession;
+}
+
+
+} } // namespace Poco::Net