HTTPSessionInstantiator.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // HTTPSessionInstantiator.h
  3. //
  4. // Library: Net
  5. // Package: HTTPClient
  6. // Module: HTTPSessionInstantiator
  7. //
  8. // Definition of the HTTPSessionInstantiator class.
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Net_HTTPSessionInstantiator_INCLUDED
  16. #define Net_HTTPSessionInstantiator_INCLUDED
  17. #include "Poco/Net/Net.h"
  18. #include "Poco/Net/HTTPSession.h"
  19. #include "Poco/URI.h"
  20. namespace Poco {
  21. namespace Net {
  22. class HTTPClientSession;
  23. class Net_API HTTPSessionInstantiator
  24. /// A factory for HTTPClientSession objects.
  25. ///
  26. /// Creates a HTTP session for a given URI.
  27. /// A HTTPSessionInstantiator is not used directly.
  28. /// Instances are registered with a HTTPSessionFactory,
  29. /// and used through it.
  30. {
  31. public:
  32. HTTPSessionInstantiator();
  33. /// Creates the HTTPSessionInstantiator.
  34. virtual ~HTTPSessionInstantiator();
  35. /// Destroys the HTTPSessionInstantiator.
  36. virtual HTTPClientSession* createClientSession(const Poco::URI& uri);
  37. /// Creates a HTTPClientSession for the given URI.
  38. static void registerInstantiator();
  39. /// Registers the instantiator with the global HTTPSessionFactory.
  40. static void unregisterInstantiator();
  41. /// Unregisters the factory with the global HTTPSessionFactory.
  42. protected:
  43. void setProxy(const std::string& host, Poco::UInt16 port);
  44. /// Sets the proxy host and port.
  45. /// Called by HTTPSessionFactory.
  46. const std::string& proxyHost() const;
  47. /// Returns the proxy post.
  48. Poco::UInt16 proxyPort() const;
  49. /// Returns the proxy port.
  50. void setProxyCredentials(const std::string& username, const std::string& password);
  51. /// Sets the username and password for proxy authorization (Basic auth only).
  52. const std::string& proxyUsername() const;
  53. /// Returns the username for proxy authorization.
  54. const std::string& proxyPassword() const;
  55. /// Returns the password for proxy authorization.
  56. private:
  57. std::string _proxyHost;
  58. Poco::UInt16 _proxyPort;
  59. std::string _proxyUsername;
  60. std::string _proxyPassword;
  61. friend class HTTPSessionFactory;
  62. };
  63. //
  64. // inlines
  65. //
  66. inline const std::string& HTTPSessionInstantiator::proxyHost() const
  67. {
  68. return _proxyHost;
  69. }
  70. inline Poco::UInt16 HTTPSessionInstantiator::proxyPort() const
  71. {
  72. return _proxyPort;
  73. }
  74. inline const std::string& HTTPSessionInstantiator::proxyUsername() const
  75. {
  76. return _proxyUsername;
  77. }
  78. inline const std::string& HTTPSessionInstantiator::proxyPassword() const
  79. {
  80. return _proxyPassword;
  81. }
  82. } } // namespace Poco::Net
  83. #endif // Net_HTTPSessionInstantiator_INCLUDED