internal: Allow use for only X-Accel-Redir (closes #1020)

(allow no arguments of paths to protect)
This commit is contained in:
Matthew Holt 2017-08-09 10:36:54 -06:00
parent 617988844b
commit b5ec462299
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
3 changed files with 9 additions and 5 deletions

View File

@ -32,7 +32,6 @@ func isInternalRedirect(w http.ResponseWriter) bool {
// ServeHTTP implements the httpserver.Handler interface.
func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// Internal location requested? -> Not found.
for _, prefix := range i.Paths {
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"
r.URL.Path = iw.Header().Get(redirectHeader)
iw.ClearHeader()
status, err = i.Next.ServeHTTP(iw, r)
}

View File

@ -30,10 +30,12 @@ func internalParse(c *caddy.Controller) ([]string, error) {
var paths []string
for c.Next() {
if !c.NextArg() {
return paths, c.ArgErr()
if c.NextArg() {
paths = append(paths, c.Val())
}
if c.NextArg() {
return nil, c.ArgErr()
}
paths = append(paths, c.Val())
}
return paths, nil

View File

@ -41,10 +41,14 @@ func TestInternalParse(t *testing.T) {
shouldErr bool
expectedInternalPaths []string
}{
{`internal`, false, []string{}},
{`internal /internal`, false, []string{"/internal"}},
{`internal /internal1
internal /internal2`, false, []string{"/internal1", "/internal2"}},
{`internal /internal1 /internal2`, true, nil},
}
for i, test := range tests {
actualInternalPaths, err := internalParse(caddy.NewTestController("http", test.inputInternalPaths))