Skip to content

Kitto.Web.Response ​

Response wrappers for KittoX. TKWebResponse adapts a WebBroker TWebResponse (status, headers, cookies, content stream) and owns a stack of TKWebResponseContent buffers that accumulate the HTML/HTMX output before it is flushed to the client. The active response is kept thread-local.

TKWebResponseContent class ​

Simplified response content container for KittoX (HTMX). Replaces the former TJSResponseItems which contained the full ExtJS JS generation pipeline.

pascal
procedure Clear;

Removes all accumulated HTML.

pascal
procedure AddHTML(const AHTML: string);

Appends an HTML fragment to the content.

pascal
function Consume: string;

Returns the full accumulated HTML and clears the buffer.

pascal
function GetContentType: string;

The content type for this HTML content ('text/html; charset=…').

pascal
property Charset: string read FCharset write FCharset;

The character set used for the content (default utf-8).

pascal
property Encoding: TEncoding read GetEncoding;

The text encoding matching Charset.

pascal
property Count: Integer read GetCount;

Number of HTML fragments accumulated.

TKWebResponse class ​

Wraps a WebBroker TWebResponse and is used throughout KittoX whenever a response object is needed. Exposes status code, content type, custom headers and cookies, and an Items stack of HTML content buffers that Send flushes to the underlying response.

pascal
class procedure ClearCurrent;

Frees and clears the current-thread response.

pascal
constructor Create(const AResponse: TWebResponse;

Wraps the given WebBroker response (optionally taking ownership).

pascal
property ContentType: string read GetContentType write SetContentType;

The response Content-Type header.

pascal
property StatusCode: Integer read GetStatusCode write SetStatusCode;

The HTTP status code.

pascal
procedure SetCustomHeader(const AName, AValue: string);

Sets (or replaces) a custom response header.

pascal
property CustomHeaders: TStrings read GetCustomHeaders;

The custom response headers collection.

pascal
procedure SetCookie(const AName, AValue: string;

Writes a simple cookie (name/value/expiry).

pascal
procedure SetSecureCookie(const AName, AValue: string;

Writes a cookie with the full set of attributes needed by JWT auth: Path, HttpOnly, Secure, SameSite. Pass an empty path to use '/'. ASameSite values: 'Strict' | 'Lax' | 'None' | '' (omit attribute).

pascal
function HasItems: Boolean;

True if any HTML content has been accumulated in Items.

pascal
property Items: TKWebResponseContent read GetItems;

The top HTML content buffer (the HTMX/HTML output pipeline).

pascal
procedure Send;

Generates content for all the Items and sets Content/ContentStream and ContentType accordingly. Then finalizes the response. Called as a final act after all request handlers have had a chance at contributing to it.

pascal
procedure ReplaceContentStream(const AStream: TStream);

Takes care of freeing a previous content stream, if any, before assigning a new one.

Released under Apache License, Version 2.0.