Commit 4588812d authored by Abiola Ibrahim's avatar Abiola Ibrahim

Gzip: Fix wildcard extension bug.

parent 7dbe4228
......@@ -43,7 +43,7 @@ func gzipParse(c *Controller) ([]gzip.Config, error) {
return configs, c.ArgErr()
}
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)
}
extFilter.Exts.Add(e)
......
......@@ -68,6 +68,11 @@ func TestGzip(t *testing.T) {
level 3
}
`, false},
{`gzip { not /file
ext *
level 1
}
`, false},
}
for i, test := range tests {
c := NewTestController(test.input)
......
......@@ -33,14 +33,14 @@ type ExtFilter struct {
}
// extWildCard is the wildcard for extensions.
const extWildCard = "*"
const ExtWildCard = "*"
// ShouldCompress checks if the request file extension matches any
// of the registered extensions. It returns true if the extension is
// found and false otherwise.
func (e ExtFilter) ShouldCompress(r *http.Request) bool {
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.
......
......@@ -73,6 +73,13 @@ func TestExtFilter(t *testing.T) {
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) {
......
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