Daraja HTTP Framework 3.0.7-SNAPSHOT
HTTP server framework for Object Pascal
Loading...
Searching...
No Matches
TdjWebComponent Class Reference

A base class which can be subclassed to create a HTTP component for a Web site. More...

Inheritance diagram for TdjWebComponent:
TdjGenericWebComponent IWebComponent TdjWebComponentHolder TdjWebComponentHolders

Public Member Functions

 TdjWebComponent ()
 ~TdjWebComponent ()
TIdHTTPSession GetSession (TdjServerContext Context, TdjRequest Request, TdjResponse Response, const Boolean Create=True)
 Get or create a HTTP session.
IWebComponentConfig GetWebComponentConfig ()
 Returns a IWebComponentConfig object, which contains initialization parameters for this component.
 Init ()
 A convenience method which can be overridden so that there is no need to call inherited Init(config).
 Init (const IWebComponentConfig Config)
 Called by the container on startup.
 Service (TdjServerContext Context, TdjRequest Request, TdjResponse Response)
 Handle a HTTP request.

Public Attributes

IWebComponentConfig Config

Protected Member Functions

 OnDelete (TdjRequest Request, TdjResponse Response)
 Called by the server to handle a DELETE request.
 OnGet (TdjRequest Request, TdjResponse Response)
 Called by the server (via the service method) to allow a component to handle a GET request.
TDateTime OnGetLastModified (TdjRequest Request)
 Returns the time the WebComponent object was last modified.
 OnHead (TdjRequest Request, TdjResponse Response)
 Called by the server (via the service method) to allow a component to handle a HEAD request.
 OnOptions (TdjRequest Request, TdjResponse Response)
 Called by the server (via the service method) to allow a component to handle a OPTIONS request.
 OnPatch (TdjRequest Request, TdjResponse Response)
 Called by the server to handle a PATCH request.
 OnPost (TdjRequest Request, TdjResponse Response)
 Called by the server to handle a POST request.
 OnPut (TdjRequest Request, TdjResponse Response)
 Called by the server to handle a PUT request.
 OnTrace (TdjRequest Request, TdjResponse Response)
 Called by the server to handle a TRACE request.

Detailed Description

A base class which can be subclassed to create a HTTP component for a Web site.

A subclass of TdjWebComponent must override at least one method, usually one of these:

  • OnGet, if the web component supports HTTP GET requests
  • OnPost, for HTTP POST requests
  • OnPut, for HTTP PUT requests
  • OnDelete, for HTTP DELETE requests

Constructor & Destructor Documentation

◆ TdjWebComponent()

TdjWebComponent::TdjWebComponent ( )

◆ ~TdjWebComponent()

TdjWebComponent::~TdjWebComponent ( )

References TdjWebComponent().

Member Function Documentation

◆ GetSession()

TIdHTTPSession TdjGenericWebComponent::GetSession ( TdjServerContext Context,
TdjRequest Request,
TdjResponse Response,
const Boolean Create = True )
inherited

Get or create a HTTP session.

Note
it requires the current TdjServerContext so calling it from one of the HTTP method handlers is not possible. It can be called from the Servive method.
if the context was created with the Auto Session option, this method will always return a session independent of the Create parameter
Parameters
ContextHTTP server context
RequestHTTP request
ResponseHTTP response
Createif True, create a session if no one exists
Returns
HTTP session

◆ GetWebComponentConfig()

IWebComponentConfig TdjGenericWebComponent::GetWebComponentConfig ( )
inherited

Returns a IWebComponentConfig object, which contains initialization parameters for this component.

Exceptions
EWebComponentExceptionif the method is called before the component has been initialized.

Implements IWebComponent.

◆ Init() [1/2]

TdjGenericWebComponent::Init ( )
inherited

A convenience method which can be overridden so that there is no need to call inherited Init(config).

◆ Init() [2/2]

TdjGenericWebComponent::Init ( const IWebComponentConfig Config)
inherited

Called by the container on startup.

Note
if this method is overridden, the overriding code must also call inherited Init.
Parameters
Configthe configuration
Exceptions
EWebComponentExceptionif initialization failed

Implements IWebComponent.

Referenced by ~TdjGenericWebComponent().

◆ OnDelete()

TdjWebComponent::OnDelete ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server to handle a DELETE request.

Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs

◆ OnGet()

TdjWebComponent::OnGet ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server (via the service method) to allow a component to handle a GET request.

◆ OnGetLastModified()

TDateTime TdjWebComponent::OnGetLastModified ( TdjRequest Request)
protected

Returns the time the WebComponent object was last modified.

If the time is unknown, this method returns 0 (the default).

WebComponents that support HTTP GET requests and can quickly determine their last modification time should override this method. This makes browser and proxy caches work more effectively, reducing the load on server and network resources.

Parameters
RequestHTTP request
Returns
the last modified timestamp

References TdjWebComponent().

◆ OnHead()

TdjWebComponent::OnHead ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server (via the service method) to allow a component to handle a HEAD request.

◆ OnOptions()

TdjWebComponent::OnOptions ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server (via the service method) to allow a component to handle a OPTIONS request.

◆ OnPatch()

TdjWebComponent::OnPatch ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server to handle a PATCH request.

Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs
See also
http://tools.ietf.org/html/rfc5789

References TdjWebComponent().

Referenced by OnPost().

◆ OnPost()

TdjWebComponent::OnPost ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server to handle a POST request.

Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs

References OnPatch().

◆ OnPut()

TdjWebComponent::OnPut ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server to handle a PUT request.

Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs

◆ OnTrace()

TdjWebComponent::OnTrace ( TdjRequest Request,
TdjResponse Response )
protected

Called by the server to handle a TRACE request.

Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs

◆ Service()

TdjWebComponent::Service ( TdjServerContext Context,
TdjRequest Request,
TdjResponse Response )

Handle a HTTP request.

The status code of the response always should be set for a component that throws or sends an error.

Note
a custom Web Component should not override this method.
Parameters
ContextHTTP server context
RequestHTTP request
ResponseHTTP response
Exceptions
EWebComponentExceptionif an exception occurs that interferes with the component's normal operation

Implements IWebComponent.

References TdjWebComponent().

Member Data Documentation

◆ Config

IWebComponentConfig TdjGenericWebComponent::Config
inherited

Referenced by ~TdjGenericWebComponent().