mirror of
https://github.com/go-gitea/gitea
synced 2024-11-18 08:04:25 +00:00
957c3fcb59
Fix #17880 Co-authored-by: Lauris BH <lauris@nix.lv>
21 lines
519 B
Go
Vendored
21 lines
519 B
Go
Vendored
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// PageRoute is a simple middleware which allows you to route a static GET request
|
|
// at the middleware stack level.
|
|
func PageRoute(path string, handler http.Handler) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "GET" && strings.EqualFold(r.URL.Path, path) {
|
|
handler.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|