mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-05 18:44:58 +03:00
Clean URL middleware handles URLs ending with /
This commit is contained in:
parent
ba0d63d722
commit
13d9bcc0c7
1 changed files with 5 additions and 3 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
@ -41,10 +42,11 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
||||||
|
|
||||||
// ServeHTTP implements the http.Handler interface.
|
// ServeHTTP implements the http.Handler interface.
|
||||||
func (e Extensionless) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (e Extensionless) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if path.Ext(r.URL.Path) == "" {
|
urlpath := strings.TrimSuffix(r.URL.Path, "/")
|
||||||
|
if path.Ext(urlpath) == "" {
|
||||||
for _, ext := range e.Extensions {
|
for _, ext := range e.Extensions {
|
||||||
if resourceExists(e.Root, r.URL.Path+ext) {
|
if resourceExists(e.Root, urlpath+ext) {
|
||||||
r.URL.Path = r.URL.Path + ext
|
r.URL.Path = urlpath + ext
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue