HTTPServerParams.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // HTTPServerParams.h
  3. //
  4. // Library: Net
  5. // Package: HTTPServer
  6. // Module: HTTPServerParams
  7. //
  8. // Definition of the HTTPServerParams class.
  9. //
  10. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Net_HTTPServerParams_INCLUDED
  16. #define Net_HTTPServerParams_INCLUDED
  17. #include "Poco/Net/Net.h"
  18. #include "Poco/Net/TCPServerParams.h"
  19. namespace Poco {
  20. namespace Net {
  21. class Net_API HTTPServerParams: public TCPServerParams
  22. /// This class is used to specify parameters to both the
  23. /// HTTPServer, as well as to HTTPRequestHandler objects.
  24. ///
  25. /// Subclasses may add new parameters to the class.
  26. {
  27. public:
  28. typedef Poco::AutoPtr<HTTPServerParams> Ptr;
  29. HTTPServerParams();
  30. /// Creates the HTTPServerParams.
  31. ///
  32. /// Sets the following default values:
  33. /// - timeout: 60 seconds
  34. /// - keepAlive: true
  35. /// - maxKeepAliveRequests: 0
  36. /// - keepAliveTimeout: 10 seconds
  37. void setServerName(const std::string& serverName);
  38. /// Sets the name and port (name:port) that the server uses to identify itself.
  39. ///
  40. /// If this is not set to valid DNS name for your host, server-generated
  41. /// redirections will not work.
  42. const std::string& getServerName() const;
  43. /// Returns the name and port (name:port) that the server uses to identify itself.
  44. void setSoftwareVersion(const std::string& softwareVersion);
  45. /// Sets the server software name and version that the server uses to identify
  46. /// itself. If this is set to a non-empty string, the server will
  47. /// automatically include a Server header field with the value given
  48. /// here in every response it sends.
  49. ///
  50. /// The format of the softwareVersion string should be name/version
  51. /// (e.g. MyHTTPServer/1.0).
  52. const std::string& getSoftwareVersion() const;
  53. /// Returns the server software name and version that the server uses to
  54. /// identify itself.
  55. void setTimeout(const Poco::Timespan& timeout);
  56. /// Sets the connection timeout for HTTP connections.
  57. const Poco::Timespan& getTimeout() const;
  58. /// Returns the connection timeout for HTTP connections.
  59. void setKeepAlive(bool keepAlive);
  60. /// Enables (keepAlive == true) or disables (keepAlive == false)
  61. /// persistent connections.
  62. bool getKeepAlive() const;
  63. /// Returns true iff persistent connections are enabled.
  64. void setKeepAliveTimeout(const Poco::Timespan& timeout);
  65. /// Sets the connection timeout for HTTP connections.
  66. const Poco::Timespan& getKeepAliveTimeout() const;
  67. /// Returns the connection timeout for HTTP connections.
  68. void setMaxKeepAliveRequests(int maxKeepAliveRequests);
  69. /// Specifies the maximum number of requests allowed
  70. /// during a persistent connection. 0 means unlimited
  71. /// connections.
  72. int getMaxKeepAliveRequests() const;
  73. /// Returns the maximum number of requests allowed
  74. /// during a persistent connection, or 0 if
  75. /// unlimited connections are allowed.
  76. protected:
  77. virtual ~HTTPServerParams();
  78. /// Destroys the HTTPServerParams.
  79. private:
  80. std::string _serverName;
  81. std::string _softwareVersion;
  82. Poco::Timespan _timeout;
  83. bool _keepAlive;
  84. int _maxKeepAliveRequests;
  85. Poco::Timespan _keepAliveTimeout;
  86. };
  87. //
  88. // inlines
  89. //
  90. inline const std::string& HTTPServerParams::getServerName() const
  91. {
  92. return _serverName;
  93. }
  94. inline const std::string& HTTPServerParams::getSoftwareVersion() const
  95. {
  96. return _softwareVersion;
  97. }
  98. inline const Poco::Timespan& HTTPServerParams::getTimeout() const
  99. {
  100. return _timeout;
  101. }
  102. inline bool HTTPServerParams::getKeepAlive() const
  103. {
  104. return _keepAlive;
  105. }
  106. inline int HTTPServerParams::getMaxKeepAliveRequests() const
  107. {
  108. return _maxKeepAliveRequests;
  109. }
  110. inline const Poco::Timespan& HTTPServerParams::getKeepAliveTimeout() const
  111. {
  112. return _keepAliveTimeout;
  113. }
  114. } } // namespace Poco::Net
  115. #endif // Net_HTTPServerParams_INCLUDED