diff options
-rw-r--r-- | server.go | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -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: "/", }) } } |