clean up redirect codes

This commit is contained in:
iacore
2024-08-27 16:26:48 +00:00
committed by VnPower
parent c9f3884f92
commit 26864022d4
6 changed files with 16 additions and 10 deletions
+4 -4
View File
@@ -5,12 +5,12 @@
- To access `/:abc`, use `r.PathValue("abc")`.
- Want to associate arbitrary value with a request? Use `r.Context.Value()`.
- Don't use `r.Response`. It's `nil`.
- Only use the following HTTP status codes:
- 303 StatusSeeOther: set method to GET
- 307 StatusTemporaryRedirect: method and body not changed
- 308 StatusPermanentRedirect: method and body not changed
## todo
- correct redirect status codes. currently i put in whatever.
- 303 StatusSeeOther: set method to GET
- 307 Temporary: method and body not changed
- 308 Permanent: method and body not changed
- add limiter (maybe it should be in nginx)
- add caching (maybe it should be in nginx)
+1 -1
View File
@@ -226,7 +226,7 @@ func defineRoutes() *mux.Router {
// Legacy illust URL
router.HandleFunc("/member_illust.php", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/artworks/"+utils.CompatRequest{Request: r}.Query("illust_id"), http.StatusFound)
http.Redirect(w, r, "/artworks/"+utils.CompatRequest{Request: r}.Query("illust_id"), http.StatusPermanentRedirect)
}).Methods("GET")
// Proxy routes
+1 -2
View File
@@ -45,8 +45,7 @@ func RankingCalendarPicker(w http.ResponseWriter, r CompatRequest) error {
return utils.RedirectToRoute(w, r,"/rankingCalendar", map[string]string{
"mode": mode,
"date": date,
}, http.StatusFound)
})
}
func RankingCalendarPage(w http.ResponseWriter, r CompatRequest) error {
+1 -1
View File
@@ -69,5 +69,5 @@ func AdvancedTagPost(w http.ResponseWriter, r CompatRequest) error {
"tool": r.Query("tool", r.FormValue("tool")),
"scd": r.Query("scd", r.FormValue("scd")),
"ecd": r.Query("ecd", r.FormValue("ecd")),
}, http.StatusFound)
})
}
+7
View File
@@ -146,3 +146,10 @@ rules:
# func $NAME(w http.ResponseWriter, r *http.Request) error {
# $...I
# }
- id: rule-11
message: "Use StatusSeeOther or StatusPermanentRedirect"
languages: [go]
severity: WARNING
patterns:
- pattern: |
StatusFound
+2 -2
View File
@@ -55,12 +55,12 @@ func SendString(w http.ResponseWriter, text string) error {
return err
}
func RedirectToRoute(w http.ResponseWriter, r CompatRequest, path string, query_params map[string]string, code int) error {
func RedirectToRoute(w http.ResponseWriter, r CompatRequest, path string, query_params map[string]string) error {
query := url.Values{}
for k, v := range query_params {
query.Add(k, v)
}
http.Redirect(w, r.Request, path+query.Encode(), code)
http.Redirect(w, r.Request, path+query.Encode(), http.StatusSeeOther)
return nil
}