mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-08 11:58:49 +03:00
24 lines
464 B
Go
24 lines
464 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/mholt/caddy/config"
|
||
|
)
|
||
|
|
||
|
// Rewrite is middleware for rewriting requests internally to
|
||
|
// a different path.
|
||
|
func Rewrite(rewrites []config.Rewrite) Middleware {
|
||
|
return func(next http.HandlerFunc) http.HandlerFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
for _, rule := range rewrites {
|
||
|
if r.URL.Path == rule.From {
|
||
|
r.URL.Path = rule.To
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
next(w, r)
|
||
|
}
|
||
|
}
|
||
|
}
|