#include <Pt/Http/Server.h>
Listening HTTP server. More...
Inherits Connectable, and NonCopyable.
Public Member Functions | |
| Server () | |
| Default Constructor. | |
| Server (System::EventLoop &loop) | |
| Construct with event loop. | |
| Server (System::EventLoop &loop, const Net::Endpoint &ep) | |
| Construct with event loop and listen endpoint. | |
| ~Server () | |
| Destructor. | |
| System::EventLoop * | loop () |
| Returns the used event loop. | |
| void | setActive (System::EventLoop &loop) |
| Sets the event loop to use. | |
| std::size_t | timeout () const |
| Returns the timeout in msecs. | |
| void | setTimeout (std::size_t ms) |
| Sets the timeout in msecs. | |
| void | setSecure (Ssl::Context &ctx) |
| Enables HTTPS with ctx. | |
| std::size_t | maxThreads () const |
| Returns the maximum number of server threads. | |
| void | setMaxThreads (std::size_t m) |
| Sets the maximum number of server threads. | |
| std::size_t | keepAliveTimeout () const |
| Returns the keepalive timeout in msecs. | |
| void | setKeepAliveTimeout (std::size_t ms) |
| Sets the keepalive timeout in msecs. | |
| std::size_t | maxRequestSize () const |
| Returns the maximum size of a request in bytes. | |
| void | setMaxRequestSize (std::size_t maxSize) |
| Sets the maximum size of a request in bytes. | |
| void | listen (const Net::Endpoint &ep) |
| Start listening on endpoint. | |
| void | listen (const Net::Endpoint &ep, const Net::TcpServerOptions &opts) |
| Start listening on endpoint. | |
| void | cancel () |
| Cancel all operations. | |
| void | addServlet (Servlet &servlet) |
| Adds a servlet. | |
| void | removeServlet (Servlet &servlet) |
| Removes a servlet. | |
Server is the listening HTTP service in the server model. It binds a local Endpoint and accepts connections, but it does not implement a resource. Incoming requests are mapped by servlets that have been added with addServlet(). The first servlet that maps the request handles it. removeServlet() unregisters a servlet.
All server I/O is asynchronous, so the server needs an EventLoop, passed to a constructor or to setActive(). The loop does not own the server. listen() binds the local endpoint, optionally with TcpServerOptions, and a second listen replaces the previous binding. cancel() stops accepting and pending work.
setSecure() assigns a Pt::Ssl::Context so the server accepts only HTTPS connections. Further use of servlets and responders is unchanged. Certificate and handshake details live in the SSL module.
setMaxThreads() bounds worker threads. setTimeout() and setKeepAliveTimeout() bound idle I/O and persistent connections, and setMaxRequestSize() rejects a request whose size exceeds that limit.