HTTPSessionInstantiator.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "Poco/Net/HTTPSessionInstantiator.h"
  14. #include "Poco/Net/HTTPSessionFactory.h"
  15. #include "Poco/Net/HTTPClientSession.h"
  16. using Poco::URI;
  17. namespace Poco {
  18. namespace Net {
  19. HTTPSessionInstantiator::HTTPSessionInstantiator():
  20. _proxyPort(0)
  21. {
  22. }
  23. HTTPSessionInstantiator::~HTTPSessionInstantiator()
  24. {
  25. }
  26. HTTPClientSession* HTTPSessionInstantiator::createClientSession(const Poco::URI& uri)
  27. {
  28. poco_assert (uri.getScheme() == "http");
  29. HTTPClientSession* pSession = new HTTPClientSession(uri.getHost(), uri.getPort());
  30. if (!proxyHost().empty())
  31. {
  32. pSession->setProxy(proxyHost(), proxyPort());
  33. pSession->setProxyCredentials(proxyUsername(), proxyPassword());
  34. }
  35. return pSession;
  36. }
  37. void HTTPSessionInstantiator::registerInstantiator()
  38. {
  39. HTTPSessionFactory::defaultFactory().registerProtocol("http", new HTTPSessionInstantiator);
  40. }
  41. void HTTPSessionInstantiator::unregisterInstantiator()
  42. {
  43. HTTPSessionFactory::defaultFactory().unregisterProtocol("http");
  44. }
  45. void HTTPSessionInstantiator::setProxy(const std::string& host, Poco::UInt16 port)
  46. {
  47. _proxyHost = host;
  48. _proxyPort = port;
  49. }
  50. void HTTPSessionInstantiator::setProxyCredentials(const std::string& username, const std::string& password)
  51. {
  52. _proxyUsername = username;
  53. _proxyPassword = password;
  54. }
  55. } } // namespace Poco::Net