Skip to content

Kitto.Web.Request

Request wrappers for KittoX. TKWebRequest adapts a WebBroker TWebRequest and adds Kitto-specific helpers (query/form/cookie/header access, single URL-decoding, JSON body parsing, Ajax/refresh and mobile-browser detection), kept thread-local. TKWebRequestInfo snapshots request data for use after the request object is destroyed.

TKWebRequest class

Wraps a TWebRequest object and is used throughout Kitto whenever a request object is needed. Adds Kitto-specific funcionality. Not inheriting from TWebRequest (or specific derived classes) allows to transparently support whatever deployment options WebBroker provides, while still keeping Kitto-specific additional functionality.

pascal
class procedure ClearCurrent;

Frees and clears the current-thread request.

pascal
constructor Create(const ARequest: TWebRequest;

Wraps the given WebBroker request (optionally taking ownership).

pascal
property IsAjax: Boolean read GetIsAjax;

True if the request is an XMLHttpRequest (X-Requested-With).

pascal
property IsRefresh: Boolean read GetIsRefresh;

True if the request is a browser refresh (non-Ajax, Cache-Control: max-age=0).

pascal
property QueryTree: TEFTree read GetQueryTree;

Returns all request query fields (names and decoded values) as a tree object, which is only alive as long as the request object is. Note: All values are treated as strings.

pascal
property JSONContentTree: TEFTree read GetJSONContentTree;

Parses the request content as a JSON object and returns the data as a tree object, which is only alive as long as the request object is. Note: All values are treated as strings.

pascal
property Content: string read GetContent;

The raw request body (e.g. a JSON payload for a REST call).

pascal
function GetQueryField(const AName: string): string;

Decodes and returns the value of the query field with the given name, or '' if not found.

pascal
function GetHeaderField(const AName: string): string;

Returns the value of the header field with the given name, or '' if not found.

pascal
function GetFormField(const AName: string): string;

Decodes and returns the value of the POST form field with the given name (from ContentFields), or '' if not found.

pascal
function GetContentFields: TStrings;

Returns the POST body fields as a TStrings of name=value pairs (the RTL ContentFields), by reference — owned by the request, do not free. Backs the [TKXFormBody] parameter binding.

pascal
function GetField(const AName: string): string;

Returns the value of a field searching first in ContentFields (POST body), then in QueryFields (URL query string). Returns '' if not found.

pascal
function HasField(const AName: string): Boolean;

Returns True if a field with the given name is present in the POST body or in the URL query string. Distinguishes "field not posted" from "field posted with empty value", which GetField/GetFormField alone cannot do.

pascal
function GetCookie(const AName: string): string;

Returns the value of the cookie with the given name, or '' if not found.

pascal
function IsBrowserIPhone: Boolean;

True if the User-Agent indicates an iPhone.

pascal
function IsBrowserIPad: Boolean;

True if the User-Agent indicates an iPad.

pascal
function IsMobileBrowser: Boolean;

True if the User-Agent indicates a mobile device (iPhone/iPad/Android/Windows Phone).

pascal
function IsBrowserWindowsPhone: Boolean;

True if the User-Agent indicates a Windows Phone.

pascal
function IsPageRefresh(const AURLDocument: string): Boolean;

True if the specified URL is interpreted as a page refresh (which in Kitto means a new session).

pascal
property AcceptLanguage: string read GetAcceptLanguage;

The Accept-Language header value.

pascal
property Language: string read GetLanguage;

The requested language (from the Language query field).

pascal
property UserAgent: string read GetUserAgent;

The User-Agent header value.

pascal
property RemoteAddr: string read GetRemoteAddr;

The client's remote (IP) address.

pascal
property Host: string read GetHost;

The host the client addressed the request to (Host header), including the port when the client sent one.

pascal
property Timestamp: TDateTime read GetTimestamp;

The request timestamp (falls back to Now if the request has no date).

pascal
property Files: TAbstractWebRequestFiles read GetFiles;

The uploaded files of a multipart request.

pascal
function Method: string;

HTTP method of the request (GET, POST, etc.).

pascal
function ContentType: string;

The request body's media type (Content-Type header), e.g. 'application/json'.

TKWebRequestInfo record

Keeps track of some request data to be accessed after the request object itself is destroyed.

pascal
procedure ClearData;

Resets all captured fields to empty.

pascal
procedure SetData(const ARequest: TKWebRequest);

Captures UserAgent/ClientAddress/Timestamp from the given request.

Released under Apache License, Version 2.0.