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
20using Poco::URI;
21
22
23namespace Poco {
24namespace Net {
25
26
27HTTPSessionInstantiator::HTTPSessionInstantiator():
28 _proxyPort(0)
29{
30}
31
32
33HTTPSessionInstantiator::~HTTPSessionInstantiator()
34{
35}
36
37
38HTTPClientSession* 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
51void HTTPSessionInstantiator::registerInstantiator()
52{
53 HTTPSessionFactory::defaultFactory().registerProtocol("http", new HTTPSessionInstantiator);
54}
55
56
57void HTTPSessionInstantiator::unregisterInstantiator()
58{
59 HTTPSessionFactory::defaultFactory().unregisterProtocol("http");
60}
61
62
63void HTTPSessionInstantiator::setProxy(const std::string& host, Poco::UInt16 port)
64{
65 _proxyHost = host;
66 _proxyPort = port;
67}
68
69
70void 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