A base class which can be subclassed to create a HTTP component for a Web site.
More...
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).
- a 405 response, whether from a not-overridden handler or set explicitly, always carries an Allow header listing the methods this component supports.
- OPTIONS is answered by the framework itself unless OnOptions is overridden: the default response is 200 with an Allow header and no body (see OnOptions).
- an unrecognised HTTP method responds with 501 Not Implemented.
- conditional GET/HEAD is supported through OnGetLastModified (If-Modified-Since) and OnGetETag (If-None-Match). If a request carries If-None-Match, it alone decides the outcome, per RFC 7232 Section 3.3; If-Modified-Since is only consulted when the request has no If-None-Match. A 304 response carries Date, and Last-Modified / ETag whenever the component supplies them.
-
Threading: the framework creates exactly one instance of each registered component, and every concurrent request runs through that same instance's Service method on its own thread. Do not keep per-request state in instance fields — two requests handled at the same time will read and write the same field, corrupting each other's data. Use local variables for anything request-specific, and if state truly must be shared across requests, synchronize access to it explicitly (e.g. with a critical section).
| string TdjWebComponent::OnGetETag |
( |
TdjRequest | Request | ) |
|
|
protected |
Returns the entity tag (ETag) of the resource a GET/HEAD request would return.
If unknown, this method returns '' (the default), which means no ETag is offered and no If-None-Match comparison is done.
WebComponents that support HTTP GET requests and can cheaply compute a stable identifier for their current representation should override this method. The returned value is sent as the ETag header, quoted per RFC 7232 if not already (e.g. '"abc123"'), and compared against a request's If-None-Match header using a weak comparison (a leading 'W/' is ignored on both sides).
- Parameters
-
- Returns
- the entity tag, or '' if unknown
| 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
-
- Returns
- the last modified timestamp
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 / OnGetETag 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
-
| Request | The HTTP request to process |
| Response | The HTTP response to fill |
- Exceptions
-