mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Moved Path type around
This commit is contained in:
parent
04996b2850
commit
612d77eaab
3 changed files with 16 additions and 16 deletions
|
@ -3,7 +3,7 @@ package headers
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware/util"
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Headers is middleware that adds headers to the responses
|
// Headers is middleware that adds headers to the responses
|
||||||
|
@ -17,7 +17,7 @@ type Headers struct {
|
||||||
// adding headers to the response according to the configured rules.
|
// adding headers to the response according to the configured rules.
|
||||||
func (h *Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, rule := range h.rules {
|
for _, rule := range h.rules {
|
||||||
if util.Path(r.URL.Path).Matches(rule.Url) {
|
if middleware.Path(r.URL.Path).Matches(rule.Url) {
|
||||||
for _, header := range rule.Headers {
|
for _, header := range rule.Headers {
|
||||||
w.Header().Set(header.Name, header.Value)
|
w.Header().Set(header.Name, header.Value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
// the servers to use, according to their configuration.
|
// the servers to use, according to their configuration.
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import "net/http"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Generator represents the outer layer of a middleware that
|
// Generator represents the outer layer of a middleware that
|
||||||
|
@ -35,13 +32,3 @@ type (
|
||||||
Port() string
|
Port() string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Path represents a URI path, maybe with pattern characters.
|
|
||||||
type Path string
|
|
||||||
|
|
||||||
// Path matching will probably not always be a direct
|
|
||||||
// comparison; this method assures that paths can be
|
|
||||||
// easily matched.
|
|
||||||
func (p Path) Matches(other string) bool {
|
|
||||||
return strings.HasPrefix(string(p), other)
|
|
||||||
}
|
|
||||||
|
|
13
middleware/path.go
Normal file
13
middleware/path.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// Path represents a URI path, maybe with pattern characters.
|
||||||
|
type Path string
|
||||||
|
|
||||||
|
// Path matching will probably not always be a direct
|
||||||
|
// comparison; this method assures that paths can be
|
||||||
|
// easily matched.
|
||||||
|
func (p Path) Matches(other string) bool {
|
||||||
|
return strings.HasPrefix(string(p), other)
|
||||||
|
}
|
Loading…
Reference in a new issue