mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-07 05:21:04 +08:00
Moved extensionless middleware into its own package
This commit is contained in:
@ -1,26 +1,30 @@
|
|||||||
package middleware
|
// Extensionless is middleware for clean URLs. A root path is
|
||||||
|
// passed in as well as possible extensions to add, internally,
|
||||||
|
// to paths requested. The first path+ext that matches a resource
|
||||||
|
// that exists will be used.
|
||||||
|
package extensionless
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Extensionless is middleware for clean URLs. A root path is
|
// New creates a new instance of middleware that assumes extensions
|
||||||
// passed in as well as possible extensions to add, internally,
|
// so the site can use cleaner, extensionless URLs
|
||||||
// to paths requested. The first path+ext that matches a resource
|
func New(c middleware.Controller) (middleware.Middleware, error) {
|
||||||
// that exists will be used.
|
|
||||||
func Extensionless(p parser) Middleware {
|
|
||||||
var extensions []string
|
var extensions []string
|
||||||
var root = p.Root() // TODO: Big gotcha! Save this now before it goes away! We can't get this later during a request!
|
var root = c.Root() // TODO: Big gotcha! Save this now before it goes away! We can't get this later during a request!
|
||||||
|
|
||||||
for p.Next() {
|
for c.Next() {
|
||||||
if !p.NextArg() {
|
if !c.NextArg() {
|
||||||
return p.ArgErr()
|
return nil, c.ArgErr()
|
||||||
}
|
}
|
||||||
extensions = append(extensions, p.Val())
|
extensions = append(extensions, c.Val())
|
||||||
for p.NextArg() {
|
for c.NextArg() {
|
||||||
extensions = append(extensions, p.Val())
|
extensions = append(extensions, c.Val())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,5 +57,5 @@ func Extensionless(p parser) Middleware {
|
|||||||
}
|
}
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
Reference in New Issue
Block a user