mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Gzip: Fix wildcard extension bug.
This commit is contained in:
parent
7dbe42286d
commit
4588812d24
4 changed files with 15 additions and 3 deletions
|
@ -43,7 +43,7 @@ func gzipParse(c *Controller) ([]gzip.Config, error) {
|
||||||
return configs, c.ArgErr()
|
return configs, c.ArgErr()
|
||||||
}
|
}
|
||||||
for _, e := range exts {
|
for _, e := range exts {
|
||||||
if !strings.HasPrefix(e, ".") {
|
if !strings.HasPrefix(e, ".") && e != gzip.ExtWildCard {
|
||||||
return configs, fmt.Errorf(`gzip: invalid extension "%v" (must start with dot)`, e)
|
return configs, fmt.Errorf(`gzip: invalid extension "%v" (must start with dot)`, e)
|
||||||
}
|
}
|
||||||
extFilter.Exts.Add(e)
|
extFilter.Exts.Add(e)
|
||||||
|
|
|
@ -68,6 +68,11 @@ func TestGzip(t *testing.T) {
|
||||||
level 3
|
level 3
|
||||||
}
|
}
|
||||||
`, false},
|
`, false},
|
||||||
|
{`gzip { not /file
|
||||||
|
ext *
|
||||||
|
level 1
|
||||||
|
}
|
||||||
|
`, false},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
c := NewTestController(test.input)
|
c := NewTestController(test.input)
|
||||||
|
|
|
@ -33,14 +33,14 @@ type ExtFilter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// extWildCard is the wildcard for extensions.
|
// extWildCard is the wildcard for extensions.
|
||||||
const extWildCard = "*"
|
const ExtWildCard = "*"
|
||||||
|
|
||||||
// ShouldCompress checks if the request file extension matches any
|
// ShouldCompress checks if the request file extension matches any
|
||||||
// of the registered extensions. It returns true if the extension is
|
// of the registered extensions. It returns true if the extension is
|
||||||
// found and false otherwise.
|
// found and false otherwise.
|
||||||
func (e ExtFilter) ShouldCompress(r *http.Request) bool {
|
func (e ExtFilter) ShouldCompress(r *http.Request) bool {
|
||||||
ext := path.Ext(r.URL.Path)
|
ext := path.Ext(r.URL.Path)
|
||||||
return e.Exts.Contains(extWildCard) || e.Exts.Contains(ext)
|
return e.Exts.Contains(ExtWildCard) || e.Exts.Contains(ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathFilter is Filter for request path.
|
// PathFilter is Filter for request path.
|
||||||
|
|
|
@ -73,6 +73,13 @@ func TestExtFilter(t *testing.T) {
|
||||||
t.Errorf("Test %v: Should not be valid filter", i)
|
t.Errorf("Test %v: Should not be valid filter", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
filter.(ExtFilter).Exts.Add(ExtWildCard)
|
||||||
|
for i, e := range exts {
|
||||||
|
r := urlRequest("file" + e)
|
||||||
|
if !filter.ShouldCompress(r) {
|
||||||
|
t.Errorf("Test %v: Should be valid filter. Wildcard used.", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPathFilter(t *testing.T) {
|
func TestPathFilter(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue