Daraja HTTP Framework 3.2.1-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
Note
Method handling notes and current limitations:
  • every On* handler that is not overridden responds with 405 Method Not Allowed, with one exception: HEAD is derived from OnGet (see OnHead). OPTIONS is not derived - override OnOptions explicitly if you need it.
  • an unrecognised HTTP method responds with 501 Not Implemented.
  • conditional GET is supported through OnGetLastModified only (If-Modified-Since); there is no ETag / If-None-Match handling.

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 it cannot be called from one of the HTTP method handlers (OnGet etc.). It can be called from the Service 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).

References TdjGenericWebComponent().

◆ 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.

References Init().

Referenced by Init().

◆ 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

References OnGet().

◆ 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.

References OnHead().

Referenced by OnDelete().

◆ 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.

The default implementation runs the same code path as a GET request, including the OnGetLastModified conditional handling, and the response body is suppressed. A component which overrides OnGet therefore answers HEAD requests with the GET headers and no content. If OnGet is not overridden either, the response is 405 Method Not Allowed.

Note
because the GET path runs in full, an expensive OnGet does its work for a HEAD request too, and any side effect of OnGet is triggered by a HEAD request as well. Override this method to handle HEAD separately.
Parameters
RequestThe HTTP request to process
ResponseThe HTTP response to fill
Exceptions
EWebComponentExceptionif an exception occurs

References OnPut().

Referenced by OnGet().

◆ 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.

References OnTrace().

◆ 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().

◆ 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

◆ 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

References TdjWebComponent(), and Service().

Referenced by OnHead().

◆ 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

Referenced by OnOptions().

◆ 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().

Referenced by OnPut().

Member Data Documentation

◆ Config

IWebComponentConfig TdjGenericWebComponent::Config
inherited