summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/server.go b/server.go
index 10cb474..4788de7 100644
--- a/server.go
+++ b/server.go
@@ -44,7 +44,7 @@ func router(w http.ResponseWriter, r *http.Request) {
Name: "redirect",
Path: "/",
})
- http.Redirect(w, r, url + lang + "/", http.StatusTemporaryRedirect)
+ http.Redirect(w, r, url+lang+"/", http.StatusTemporaryRedirect)
return
}
@@ -54,21 +54,27 @@ func router(w http.ResponseWriter, r *http.Request) {
_, err = r.Cookie("redirect")
if isSupportedLanguage(parts[0]) && parts[0] != lang {
if r.Header.Get("Referer") == "" && err != nil {
- parts[0] = lang
- path = strings.Join(parts, "/")
- http.SetCookie(w, &http.Cookie{
- Name: "redirect",
- Path: "/",
- })
- http.Redirect(w, r, url + path, http.StatusTemporaryRedirect)
+ if !errors.Is(err, http.ErrNoCookie) {
+ log.Println(err)
+ http.Error(w, "An error occured", http.StatusInternalServerError)
+ } else {
+ parts[0] = lang
+ path = strings.Join(parts, "/")
+ http.SetCookie(w, &http.Cookie{
+ Name: "redirect",
+ Path: "/",
+ })
+ http.Redirect(w, r, url+path, http.StatusTemporaryRedirect)
+ }
return
}
if r.Header.Get("Referer") != "" {
http.SetCookie(w, &http.Cookie{
- Name: CookieName,
- Value: parts[0],
- Path: "/",
+ Name: CookieName,
+ Value: parts[0],
+ Expires: time.Now().AddDate(100, 0, 0),
+ Path: "/",
})
}
}