diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-07 16:04:11 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-07 16:04:11 +0200 |
commit | 6332cce84ceabf90d8c42167148f41d98d0c28b9 (patch) | |
tree | 2dfd2bc0c5a82285b81c5c1e054c86cf51f6b1f1 | |
parent | 257d58f0a212df249c19e2159cd6871c4154fda3 (diff) |
Properly redirect the user after language selection
-rw-r--r-- | main.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -1,6 +1,7 @@ package main import ( + "cmp" "errors" "flag" "fmt" @@ -52,6 +53,16 @@ func finalHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, p.T("Page not found")) } else { + /* When a user clicks on the language button to be taken to the + language selection page, we need to set a redirect cookie so + that after selecting a language they are taken back to the + original page they came from. */ + if path == "/language" { + http.SetCookie(w, &http.Cookie{ + Name: "redirect", + Value: cmp.Or(r.Referer(), "/"), + }) + } templates.Root(nil, c).Render(r.Context(), w) } } |