Commit 612d77ea authored by Matthew Holt's avatar Matthew Holt

Moved Path type around

parent 04996b28
...@@ -3,7 +3,7 @@ package headers ...@@ -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 { ...@@ -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 @@ ...@@ -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 ( ...@@ -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)
}
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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment