mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-24 09:37:03 +01:00
Refactored ext middleware to return errors
This commit is contained in:
parent
843f6e83a9
commit
a674450198
1 changed files with 4 additions and 4 deletions
|
@ -16,7 +16,7 @@ import (
|
||||||
// Extensionless is an http.Handler that can assume an extension from clean URLs.
|
// Extensionless is an http.Handler that can assume an extension from clean URLs.
|
||||||
// It tries extensions in the order listed in Extensions.
|
// It tries extensions in the order listed in Extensions.
|
||||||
type Extensionless struct {
|
type Extensionless struct {
|
||||||
Next http.HandlerFunc
|
Next middleware.HandlerFunc
|
||||||
Root string
|
Root string
|
||||||
Extensions []string
|
Extensions []string
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
return func(next middleware.HandlerFunc) middleware.HandlerFunc {
|
||||||
return Extensionless{
|
return Extensionless{
|
||||||
Next: next,
|
Next: next,
|
||||||
Extensions: extensions,
|
Extensions: extensions,
|
||||||
|
@ -41,7 +41,7 @@ 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) (int, error) {
|
||||||
urlpath := strings.TrimSuffix(r.URL.Path, "/")
|
urlpath := strings.TrimSuffix(r.URL.Path, "/")
|
||||||
if path.Ext(urlpath) == "" {
|
if path.Ext(urlpath) == "" {
|
||||||
for _, ext := range e.Extensions {
|
for _, ext := range e.Extensions {
|
||||||
|
@ -51,7 +51,7 @@ func (e Extensionless) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.Next(w, r)
|
return e.Next(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse sets up an instance of Extensionless middleware
|
// parse sets up an instance of Extensionless middleware
|
||||||
|
|
Loading…
Reference in a new issue