|
Webserv
|
The central request dispatcher (Facade). More...
#include <Router.hpp>
Public Member Functions | |
| Router (config::ServerConfig const &cfg, MimeTypes const &mime) | |
| Constructs the Router. | |
| void | matchServerAndLocation (int port, Request &request) const |
| Populates the request with the matching server and location blocks. | |
| void | dispatch (int port, const Request &request, Response &response) const |
| Dispatches a fully parsed request to the correct handler. | |
| void | handleError (Request const &, Response &) const |
Private Member Functions | |
| void | executeHandler (Request const &request, Response &response) const |
| Internal: Selects and executes the correct handler. | |
Static Private Member Functions | |
| static void | handleError (Request const &request, Response &response, MimeTypes const &mimeTypes) |
| Populates an error response. | |
| static bool | isMethodAllowed (const Request &request) |
Private Attributes | |
| config::ServerConfig const & | config_ |
| MimeTypes const & | mimeTypes_ |
The central request dispatcher (Facade).
This class acts as the main "brain" for handling requests. It uses the ServerConfig to find the correct route, selects the appropriate handler (e.g., StaticFile, CGI), and populates an Response. It also coordinates error page generation.
| http::Router::Router | ( | config::ServerConfig const & | cfg, |
| MimeTypes const & | mime ) |
Constructs the Router.
| cfg | A constant reference to the global server configuration. |
| mime | A constant reference to the loaded MIME types. |
Dispatches a fully parsed request to the correct handler.
This is the main entry point for the Reactor. It finds the route, executes the correct handler, and formats any errors that occur.
| port | The port the connection was received on. |
| request | The fully populated client request. |
| response | The Response object to be populated by the handler. |
Internal: Selects and executes the correct handler.
|
staticprivate |
Populates an error response.
|
staticprivate |
| void http::Router::matchServerAndLocation | ( | int | port, |
| Request & | request ) const |
Populates the request with the matching server and location blocks.
This method is intended to be called by the Reactor before the body is parsed, allowing for route-specific body validation (e.g., size limits).
| port | The port the connection was received on. |
| request | The HttpRequest object to populate. |
|
private |
|
private |