0
Fork 0
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:
Matthew Holt 2015-01-29 22:08:40 -07:00
parent 04996b2850
commit 612d77eaab
3 changed files with 16 additions and 16 deletions

View file

@ -3,7 +3,7 @@ package headers
import (
"net/http"
"github.com/mholt/caddy/middleware/util"
"github.com/mholt/caddy/middleware"
)
// 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.
func (h *Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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 {
w.Header().Set(header.Name, header.Value)
}

View file

@ -2,10 +2,7 @@
// the servers to use, according to their configuration.
package middleware
import (
"net/http"
"strings"
)
import "net/http"
type (
// Generator represents the outer layer of a middleware that
@ -35,13 +32,3 @@ type (
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
View 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)
}