1 | // |
---|---|
2 | // HTTPSessionInstantiator.cpp |
3 | // |
4 | // Library: Net |
5 | // Package: HTTPClient |
6 | // Module: HTTPSessionInstantiator |
7 | // |
8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Net/HTTPSessionInstantiator.h" |
16 | #include "Poco/Net/HTTPSessionFactory.h" |
17 | #include "Poco/Net/HTTPClientSession.h" |
18 | |
19 | |
20 | using Poco::URI; |
21 | |
22 | |
23 | namespace Poco { |
24 | namespace Net { |
25 | |
26 | |
27 | HTTPSessionInstantiator::HTTPSessionInstantiator(): |
28 | _proxyPort(0) |
29 | { |
30 | } |
31 | |
32 | |
33 | HTTPSessionInstantiator::~HTTPSessionInstantiator() |
34 | { |
35 | } |
36 | |
37 | |
38 | HTTPClientSession* HTTPSessionInstantiator::createClientSession(const Poco::URI& uri) |
39 | { |
40 | poco_assert (uri.getScheme() == "http"); |
41 | HTTPClientSession* pSession = new HTTPClientSession(uri.getHost(), uri.getPort()); |
42 | if (!proxyHost().empty()) |
43 | { |
44 | pSession->setProxy(proxyHost(), proxyPort()); |
45 | pSession->setProxyCredentials(proxyUsername(), proxyPassword()); |
46 | } |
47 | return pSession; |
48 | } |
49 | |
50 | |
51 | void HTTPSessionInstantiator::registerInstantiator() |
52 | { |
53 | HTTPSessionFactory::defaultFactory().registerProtocol("http", new HTTPSessionInstantiator); |
54 | } |
55 | |
56 | |
57 | void HTTPSessionInstantiator::unregisterInstantiator() |
58 | { |
59 | HTTPSessionFactory::defaultFactory().unregisterProtocol("http"); |
60 | } |
61 | |
62 | |
63 | void HTTPSessionInstantiator::setProxy(const std::string& host, Poco::UInt16 port) |
64 | { |
65 | _proxyHost = host; |
66 | _proxyPort = port; |
67 | } |
68 | |
69 | |
70 | void HTTPSessionInstantiator::setProxyCredentials(const std::string& username, const std::string& password) |
71 | { |
72 | _proxyUsername = username; |
73 | _proxyPassword = password; |
74 | } |
75 | |
76 | |
77 | } } // namespace Poco::Net |
78 |