mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
clean up redirect codes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user