|
NetBurner 3.5.6
PDF Version |
Base class for HTTP request handlers that process requests for specific URLs and HTTP methods. More...
#include <http.h>
Inherited by AcmeAuthItem, CallBackFunctionPageHandler, CallBackWSEndPoint, HtmlConfigExposer, and HtmlPostHandler.
Public Member Functions | |
| HtmlPageHandler (const char *url, HTTP_RequestTypes rt=tGet, int accessGroup=0, bool Before_Files=false) | |
| Constructs and registers an HTTP request handler for a specific URL pattern and method. | |
| ~HtmlPageHandler () | |
| Destructor that automatically unregisters the handler from the global chain. | |
| void | MoveHandlerToLast () |
| Moves this handler to the end of the handler chain, making it function as a 404 handler. | |
| virtual int | ProcessRaw (int sock, HTTP_Request &pd)=0 |
| Pure virtual method that must be implemented to process HTTP requests. | |
| int | GetGroup () |
| Returns the access control group identifier for this handler. | |
Static Public Member Functions | |
| static HtmlPageHandler * | FindHandler (HTTP_Request &req, bool bBeforeFiles) |
| Locates the appropriate handler for an incoming HTTP request. | |
Protected Member Functions | |
| void | InsertSort (HtmlPageHandler *&ph) |
| Inserts handler into sorted linked list based on priority. | |
| int | SortValue (HtmlPageHandler *pv) |
| Compares handler priorities for sorting (-1, 0, 1) | |
| void | Remove () |
| Removes handler from the linked list. | |
| virtual bool | Match (HTTP_Request &req) |
| Determines if this handler matches the incoming request. | |
Protected Attributes | |
| HtmlPageHandler * | m_pNextHandler |
| Pointer to next handler in the linked list for efficient traversal. | |
| const char * | m_pUrlName |
| URL pattern to match. Empty string or NULL matches all requests. | |
| int | m_access_group |
| Access control group identifier for authorization checks. | |
| HTTP_RequestTypes | m_requestTypes |
| HTTP method types this handler responds to (GET, POST, etc.) | |
Base class for HTTP request handlers that process requests for specific URLs and HTTP methods.
This abstract base class provides the foundation for handling HTTP requests in NetBurner web applications. Derived classes implement specific request processing logic for particular URLs and HTTP methods (GET, POST, etc.). The class manages handler registration, URL matching, access control, and provides a linked-list structure for efficient handler lookup during request processing. Handlers can be configured to process requests before or after built-in file serving, allowing for custom processing or overriding of static content.
The handler system supports:
| HtmlPageHandler::HtmlPageHandler | ( | const char * | url, |
| HTTP_RequestTypes | rt = tGet, | ||
| int | accessGroup = 0, | ||
| bool | Before_Files = false ) |
Constructs and registers an HTTP request handler for a specific URL pattern and method.
Creates a new request handler and automatically registers it in the global handler chain. The handler will be invoked when incoming requests match the specified URL pattern and HTTP method type, subject to access control restrictions.
| url | URL pattern to handle. NULL or empty string creates a catch-all handler that matches any URL not handled by more specific handlers |
| rt | HTTP request type(s) to respond to from HTTP_RequestTypes enumeration (default: tGet for GET requests) |
| accessGroup | Access control group identifier for authorization (default: 0 for unrestricted access) |
| Before_Files | Handler priority relative to built-in file serving true: process before file serving (allows overriding static content) false: process after file serving (default: false) |
|
static |
Locates the appropriate handler for an incoming HTTP request.
Searches the handler chain to find the first handler that matches the request's URL, HTTP method, and access requirements. Handlers are evaluated in priority order.
| req | HTTP request object containing URL, method, and other request details |
| bBeforeFiles | Handler priority group to search true: search handlers that run before file serving false: search handlers that run after file serving |
|
inline |
Returns the access control group identifier for this handler.
| void HtmlPageHandler::MoveHandlerToLast | ( | ) |
Moves this handler to the end of the handler chain, making it function as a 404 handler.
Repositions the handler to be evaluated last, effectively creating a catch-all handler that processes requests not matched by any other handlers. This is commonly used to implement custom 404 error pages or fallback request processing.
|
pure virtual |
Pure virtual method that must be implemented to process HTTP requests.
This method is called when a matching request is received and must contain the actual request processing logic. Implementations should read request data, perform necessary processing, and send appropriate HTTP responses.
| sock | Socket file descriptor for the client connection |
| pd | HTTP request object containing parsed request details (headers, URL, method, body data, etc.) |
Implemented in CallBackFunctionPageHandler, and CallBackFunctionPostHandler.