Table of Contents

Struct HtmxRequestHeaders

Namespace
Ramstack.HtmxToolkit
Assembly
Ramstack.HtmxToolkit.dll

Represents strongly typed HTMX request headers.

public readonly struct HtmxRequestHeaders
Inherited Members

Remarks

HTMX 1.9.x and 2.x URI-encode a header value that the browser cannot send as is, such as Cyrillic text, and mark it with an additional *-URI-AutoEncoded header. Prompt, Target, Trigger, and TriggerName return such a value decoded. HTMX 4.x URI-encodes some values without marking them, so the properties return those values as sent.

Properties

Boosted

Gets a value indicating whether the request came from a link or form enhanced with hx-boost.

public bool Boosted { get; }

Property Value

bool

Remarks

The header name is Boosted.

CurrentUrl

Gets the current URL of the browser.

public string? CurrentUrl { get; }

Property Value

string

Remarks

The header name is CurrentUrl. If the header is not present, the property returns null.

HistoryRestoreRequest

Gets a value indicating whether the request fetches content for history restoration.

public bool HistoryRestoreRequest { get; }

Property Value

bool

Remarks

The header name is HistoryRestoreRequest.

HTMX 1.9.x and 2.x send this header after a history cache miss. HTMX 4.x has no local history cache unless an extension provides one, so it sends this header with every history restoration request.

Prompt

Gets the user's response to an hx-prompt on the client.

public string? Prompt { get; }

Property Value

string

Remarks

The header name is Prompt. If the header is not present, the property returns null.

Supported natively in HTMX 1.9.x and 2.x. In HTMX 4.x, the hx-prompt extension restores this header and URI-encodes its value.

Request

Gets a value indicating whether the request has the HX-Request header.

public bool Request { get; }

Property Value

bool

Remarks

The header name is Request.

HTMX 1.9.x and 2.x send this header with history restoration requests by default, although HTMX treats them as full page loads. IsHtmxRequest(HttpRequest) excludes such requests.

RequestType

Gets the type of the expected response.

public HtmxRequestType RequestType { get; }

Property Value

HtmxRequestType

Remarks

The header name is RequestType. If the header is not present or its value is not recognized, the property returns Unspecified.

The value is "partial" for targeted swaps and "full" for body-level or hx-select requests. HTMX 4.x sends the header itself; for HTMX 1.9.x and 2.x, the Toolkit script (htmx-toolkit.js) adds it.

A history restoration request without the header is reported as Full, because HTMX restores the whole page from it.

Source

Gets the identifier of the element that triggered the request.

public string? Source { get; }

Property Value

string

Remarks

The header name is Source. If the header is not present, the property returns null.

Supported only in HTMX 4.x. The value contains the lowercase tag name and, when the element has an ID, # followed by its URI-encoded ID. Examples include button#submit and button.

Target

Gets the identifier of the target element.

public string? Target { get; }

Property Value

string

Remarks

The header name is Target. If the header is not present, the property returns null.

In HTMX 1.9.x and 2.x, the value is the ID of the target element; the header is omitted when the target element has no ID.

In HTMX 4.x, the value contains the lowercase tag name and, when the element has an ID, # followed by its URI-encoded ID. Examples include div#results and body.

Trigger

Gets the ID of the element that triggered the request.

public string? Trigger { get; }

Property Value

string

Remarks

The header name is Trigger. If the header is not present, the property returns null.

Supported only in HTMX 1.9.x and 2.x, which omit the header when the element has no ID; HTMX 4.x identifies the source element with HX-Source instead.

TriggerName

Gets the name attribute of the element that triggered the request.

public string? TriggerName { get; }

Property Value

string

Remarks

The header name is TriggerName. If the header is not present, the property returns null.

Supported only in HTMX 1.9.x and 2.x, which omit the header when the element has no name attribute; HTMX 4.x identifies the source element with HX-Source instead.