Files
member-console/internal/server/redirect.go
T
cgalo5758 88db730fcc Add dual licensing and SPDX headers
Introduce a commercial license option alongside AGPL-3.0-only, require a
CLA for contributors, and document the terms in COMMERCIAL.md and
NOTICE. Add a script to stamp SPDX headers on Go files and apply it
across the tree.
2026-09-06 02:29:42 -05:00

28 lines
1.2 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
package server
import "net/http"
// redirectToRecord answers a mutation that navigates (design D9 "Outcome
// contract", spec form-library): a create form lands on the record it just
// made, a Settings save returns to its page. An htmx submit gets
// HX-Redirect to path and a 200 with an empty body, so htmx performs a full
// browser navigation instead of following the response itself; a native
// (non-htmx) submit gets a 303 to the same path directly, since redirecting
// only an XHR response body would never move the address bar. A bare 303 is
// never the answer to an htmx submit: htmx follows it and swaps the full
// destination page into the form's own target, nesting the operator shell
// inside itself (the panel-inside-panel defect design D9 records). Every
// caller that answers a navigating success goes through this one helper.
func redirectToRecord(w http.ResponseWriter, r *http.Request, path string) {
w.Header().Add("Vary", "HX-Request")
if r.Header.Get("HX-Request") == "true" {
w.Header().Set("HX-Redirect", path)
w.WriteHeader(http.StatusOK)
return
}
http.Redirect(w, r, path, http.StatusSeeOther)
}