axum_htmx/headers.rs
1//! HTTP headers used by htmx.
2
3use http::HeaderName;
4
5/// Indicates that the request is via an element using `hx-boost` attribute.
6///
7/// See <https://htmx.org/attributes/hx-boost/> for more information.
8pub const HX_BOOSTED: HeaderName = HeaderName::from_static("hx-boosted");
9
10/// The current URL of the browser.
11pub const HX_CURRENT_URL: HeaderName = HeaderName::from_static("hx-current-url");
12
13/// `true` if the request is for history restoration after a miss in the local
14/// history cache.
15pub const HX_HISTORY_RESTORE_REQUEST: HeaderName =
16 HeaderName::from_static("hx-history-restore-request");
17
18/// The user response to an `hx-prompt`
19///
20/// See <https://htmx.org/attributes/hx-prompt/> for more information.
21pub const HX_PROMPT: HeaderName = HeaderName::from_static("hx-prompt");
22
23pub(crate) const HX_REQUEST_STR: &str = "hx-request";
24
25/// Always `true`.
26pub const HX_REQUEST: HeaderName = HeaderName::from_static(HX_REQUEST_STR);
27
28pub(crate) const HX_TARGET_STR: &str = "hx-target";
29
30/// The `id` of the target element, if it exists.
31pub const HX_TARGET: HeaderName = HeaderName::from_static(HX_TARGET_STR);
32
33pub(crate) const HX_TRIGGER_NAME_STR: &str = "hx-trigger-name";
34
35/// The `name` of the triggered element, if it exists.
36pub const HX_TRIGGER_NAME: HeaderName = HeaderName::from_static(HX_TRIGGER_NAME_STR);
37
38/// Allows you to do a client-side redirect that does not do a full page reload.
39pub const HX_LOCATION: HeaderName = HeaderName::from_static("hx-location");
40
41/// Pushes a new URL onto the history stack.
42pub const HX_PUSH_URL: HeaderName = HeaderName::from_static("hx-push-url");
43
44/// Can be used to do a client-side redirect to a new location.
45pub const HX_REDIRECT: HeaderName = HeaderName::from_static("hx-redirect");
46
47/// If set to `true`, the client will do a full refresh on the page.
48pub const HX_REFRESH: HeaderName = HeaderName::from_static("hx-refresh");
49
50/// Replaces the currelt URL in the location bar.
51pub const HX_REPLACE_URL: HeaderName = HeaderName::from_static("hx-replace-url");
52
53/// Allows you to specify how the response value will be swapped.
54///
55/// See <https://htmx.org/attributes/hx-swap/> for more information.
56pub const HX_RESWAP: HeaderName = HeaderName::from_static("hx-reswap");
57
58/// A CSS selector that update the target of the content update to a different
59/// element on the page.
60pub const HX_RETARGET: HeaderName = HeaderName::from_static("hx-retarget");
61
62/// A CSS selector that allows you to choose which part of the response is used
63/// to be swapped in. Overrides an existing `hx-select` on the triggering
64/// element
65pub const HX_RESELECT: HeaderName = HeaderName::from_static("hx-reselect");
66
67pub(crate) const HX_TRIGGER_STR: &str = "hx-trigger";
68
69/// Can be set as a request or response header.
70///
71/// In a request, it contains the `id` of the element that triggered the
72/// request.
73///
74/// In a response, it can be used to trigger client-side events.
75///
76/// See <https://htmx.org/headers/hx-trigger/> for more information.
77pub const HX_TRIGGER: HeaderName = HeaderName::from_static(HX_TRIGGER_STR);
78
79/// Allows you to trigger client-side events.
80///
81/// See <https://htmx.org/headers/hx-trigger/> for more information.
82pub const HX_TRIGGER_AFTER_SETTLE: HeaderName = HeaderName::from_static("hx-trigger-after-settle");
83
84/// Allows you to trigger client-side events.
85///
86/// See <https://htmx.org/headers/hx-trigger/> for more information.
87pub const HX_TRIGGER_AFTER_SWAP: HeaderName = HeaderName::from_static("hx-trigger-after-swap");