Skip to content

Commit 4cc8a9a

Browse files
committedFeb 4, 2024
wip: add response header
1 parent 768f6f7 commit 4cc8a9a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
 

‎htmx.go

+37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package htmx
33
import (
44
"encoding/json"
55
"html/template"
6+
"net/http"
67

78
"github.com/gofiber/fiber/v2"
89
)
@@ -20,6 +21,42 @@ func (h HxRequestHeader) String() string {
2021
return string(h)
2122
}
2223

24+
// HxResponseHeader ...
25+
type HxResponseHeader string
26+
27+
// HxResponseHeaders ...
28+
type HxResponseHeaders struct {
29+
headers http.Header
30+
}
31+
32+
// String ...
33+
func (h HxResponseHeader) String() string {
34+
return string(h)
35+
}
36+
37+
// Set ...
38+
func (h *HxResponseHeaders) Set(k HxResponseHeader, val string) {
39+
h.headers.Set(k.String(), val)
40+
}
41+
42+
func (h *HxResponseHeaders) Get(k HxResponseHeader) string {
43+
return h.headers.Get(k.String())
44+
}
45+
46+
const (
47+
HXLocation HxResponseHeader = "HX-Location" // Allows you to do a client-side redirect that does not do a full page reload
48+
HXPushUrl HxResponseHeader = "HX-Push-Url" // pushes a new url into the history stack
49+
HXRedirect HxResponseHeader = "HX-Redirect" // can be used to do a client-side redirect to a new location
50+
HXRefresh HxResponseHeader = "HX-Refresh" // if set to "true" the client side will do a full refresh of the page
51+
HXReplaceUrl HxResponseHeader = "HX-Replace-Url" // replaces the current URL in the location bar
52+
HXReswap HxResponseHeader = "HX-Reswap" // Allows you to specify how the response will be swapped. See hx-swap for possible values
53+
HXRetarget HxResponseHeader = "HX-Retarget" // A CSS selector that updates the target of the content update to a different element on the page
54+
HXReselect HxResponseHeader = "HX-Reselect" // A CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element
55+
HXTrigger HxResponseHeader = "HX-Trigger" // allows you to trigger client side events, see the documentation for more info
56+
HXTriggerAfterSettle HxResponseHeader = "HX-Trigger-After-Settle" // allows you to trigger client side events, see the documentation for more info
57+
HXTriggerAfterSwap HxResponseHeader = "HX-Trigger-After-Swap" // allows you to trigger client side events, see the documentation for more info
58+
)
59+
2360
const (
2461
HxRequestHeaderBoosted HxRequestHeader = "HX-Boosted"
2562
HxRequestHeaderCurrentURL HxRequestHeader = "HX-Current-URL"

0 commit comments

Comments
 (0)
Please sign in to comment.