NetBurner 3.5.6
PDF Version
HtmlPageHandler Class Referenceabstract

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 HtmlPageHandlerFindHandler (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

HtmlPageHandlerm_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.)
 

Detailed Description

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:

  • URL pattern matching with wildcard support (NULL/empty string matches all URLs)
  • HTTP method filtering (GET, POST, PUT, DELETE, etc.)
  • Access group-based authorization
  • Priority ordering for handler evaluation
  • Integration with NetBurner's built-in file serving system
Note
Despite the class name "HtmlPageHandler", this class handles all HTTP request types, not just HTML pages. The name is maintained for backward compatibility with existing NetBurner applications. Handlers are automatically registered upon construction and unregistered upon destruction.

Constructor & Destructor Documentation

◆ HtmlPageHandler()

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.

Parameters
urlURL pattern to handle. NULL or empty string creates a catch-all handler that matches any URL not handled by more specific handlers
rtHTTP request type(s) to respond to from HTTP_RequestTypes enumeration (default: tGet for GET requests)
accessGroupAccess control group identifier for authorization (default: 0 for unrestricted access)
Before_FilesHandler priority relative to built-in file serving true: process before file serving (allows overriding static content) false: process after file serving (default: false)

Member Function Documentation

◆ FindHandler()

static HtmlPageHandler * HtmlPageHandler::FindHandler ( HTTP_Request & req,
bool bBeforeFiles )
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.

Parameters
reqHTTP request object containing URL, method, and other request details
bBeforeFilesHandler priority group to search true: search handlers that run before file serving false: search handlers that run after file serving
Returns
Pointer to matching handler if found, or NULL if no handler matches the request

◆ GetGroup()

int HtmlPageHandler::GetGroup ( )
inline

Returns the access control group identifier for this handler.

Returns
Access group identifier used for authorization checks, HTTP_ACCESS
See also
CheckHttpAccess for access control implementation details

◆ MoveHandlerToLast()

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.

◆ ProcessRaw()

virtual int HtmlPageHandler::ProcessRaw ( int sock,
HTTP_Request & pd )
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.

Parameters
sockSocket file descriptor for the client connection
pdHTTP request object containing parsed request details (headers, URL, method, body data, etc.)
Returns
Non-zero if the request was successfully processed and a response was sent, or 0 if the request was not processed (allows fallback to other handlers)

Implemented in CallBackFunctionPageHandler, and CallBackFunctionPostHandler.


The documentation for this class was generated from the following file: