From the documentation:
A HandlerWrapper acts as a IHandler but delegates the handle method and life cycle events to a delegate. This is primarily used to implement the Decorator pattern.
Example use cases
Example use cases for request delegation include user authentication, filtering, logging, statistics, and compression.
Nesting wrappers is allowed
By nesting of handler wrappers, the server can provide combinations of the wrappers (logging and statistics).
Example: introducing the TdjStatisticsHandler
A common use case are request statistics. The TdjStatistisHandler class gives access to information such as
- how many requests have been processed since the server startup?
- what was the minimum, maximum and average processing time for requests?
- how many errors occoured?
Instead of adding the statistics code in the web component, the server use an instance of this class which collects statistics data before and after calling wrapped web components.
A wrapper implementation must override the Handle method. In the method body, code can be executed before and after the call to the wrapped handler. Example:
procedure TdjStatisticsHandler.Handle(Target: string; Context: TdjServerContext; Request: TIdHTTPRequestInfo; Response: TIdHTTPResponseInfo); begin try Inc(FRequests); Inc(FRequestsActive); inherited; finally Dec(FRequestsActive); end; end;