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.
class procedure ClearCurrent;Frees and clears the current-thread request.
constructor Create(const ARequest: TWebRequest;Wraps the given WebBroker request (optionally taking ownership).
property IsAjax: Boolean read GetIsAjax;True if the request is an XMLHttpRequest (X-Requested-With).
property IsRefresh: Boolean read GetIsRefresh;True if the request is a browser refresh (non-Ajax, Cache-Control: max-age=0).
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.
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.
property Content: string read GetContent;The raw request body (e.g. a JSON payload for a REST call).
function GetQueryField(const AName: string): string;Decodes and returns the value of the query field with the given name, or '' if not found.
function GetHeaderField(const AName: string): string;Returns the value of the header field with the given name, or '' if not found.
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.
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.
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.
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.
function GetCookie(const AName: string): string;Returns the value of the cookie with the given name, or '' if not found.
function IsBrowserIPhone: Boolean;True if the User-Agent indicates an iPhone.
function IsBrowserIPad: Boolean;True if the User-Agent indicates an iPad.
function IsMobileBrowser: Boolean;True if the User-Agent indicates a mobile device (iPhone/iPad/Android/Windows Phone).
function IsBrowserWindowsPhone: Boolean;True if the User-Agent indicates a Windows Phone.
function IsPageRefresh(const AURLDocument: string): Boolean;True if the specified URL is interpreted as a page refresh (which in Kitto means a new session).
property AcceptLanguage: string read GetAcceptLanguage;The Accept-Language header value.
property Language: string read GetLanguage;The requested language (from the Language query field).
property UserAgent: string read GetUserAgent;The User-Agent header value.
property RemoteAddr: string read GetRemoteAddr;The client's remote (IP) address.
property Host: string read GetHost;The host the client addressed the request to (Host header), including the port when the client sent one.
property Timestamp: TDateTime read GetTimestamp;The request timestamp (falls back to Now if the request has no date).
property Files: TAbstractWebRequestFiles read GetFiles;The uploaded files of a multipart request.
function Method: string;HTTP method of the request (GET, POST, etc.).
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.
procedure ClearData;Resets all captured fields to empty.
procedure SetData(const ARequest: TKWebRequest);Captures UserAgent/ClientAddress/Timestamp from the given request.
