mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
internal: Allow use for only X-Accel-Redir (closes #1020)
(allow no arguments of paths to protect)
This commit is contained in:
parent
617988844b
commit
b5ec462299
|
@ -32,7 +32,6 @@ func isInternalRedirect(w http.ResponseWriter) bool {
|
||||||
|
|
||||||
// ServeHTTP implements the httpserver.Handler interface.
|
// ServeHTTP implements the httpserver.Handler interface.
|
||||||
func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
|
||||||
// Internal location requested? -> Not found.
|
// Internal location requested? -> Not found.
|
||||||
for _, prefix := range i.Paths {
|
for _, prefix := range i.Paths {
|
||||||
if httpserver.Path(r.URL.Path).Matches(prefix) {
|
if httpserver.Path(r.URL.Path).Matches(prefix) {
|
||||||
|
@ -50,7 +49,6 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
||||||
// "down the chain"
|
// "down the chain"
|
||||||
r.URL.Path = iw.Header().Get(redirectHeader)
|
r.URL.Path = iw.Header().Get(redirectHeader)
|
||||||
iw.ClearHeader()
|
iw.ClearHeader()
|
||||||
|
|
||||||
status, err = i.Next.ServeHTTP(iw, r)
|
status, err = i.Next.ServeHTTP(iw, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,13 @@ func internalParse(c *caddy.Controller) ([]string, error) {
|
||||||
var paths []string
|
var paths []string
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
if !c.NextArg() {
|
if c.NextArg() {
|
||||||
return paths, c.ArgErr()
|
|
||||||
}
|
|
||||||
paths = append(paths, c.Val())
|
paths = append(paths, c.Val())
|
||||||
}
|
}
|
||||||
|
if c.NextArg() {
|
||||||
|
return nil, c.ArgErr()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return paths, nil
|
return paths, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,14 @@ func TestInternalParse(t *testing.T) {
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
expectedInternalPaths []string
|
expectedInternalPaths []string
|
||||||
}{
|
}{
|
||||||
|
{`internal`, false, []string{}},
|
||||||
|
|
||||||
{`internal /internal`, false, []string{"/internal"}},
|
{`internal /internal`, false, []string{"/internal"}},
|
||||||
|
|
||||||
{`internal /internal1
|
{`internal /internal1
|
||||||
internal /internal2`, false, []string{"/internal1", "/internal2"}},
|
internal /internal2`, false, []string{"/internal1", "/internal2"}},
|
||||||
|
|
||||||
|
{`internal /internal1 /internal2`, true, nil},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
actualInternalPaths, err := internalParse(caddy.NewTestController("http", test.inputInternalPaths))
|
actualInternalPaths, err := internalParse(caddy.NewTestController("http", test.inputInternalPaths))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user