0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Merge pull request #179 from abiosoft/master

gzip: Const for wildcard extension (and added test)
This commit is contained in:
Matt Holt 2015-07-05 23:46:30 -06:00
commit 553d76dab3
4 changed files with 15 additions and 3 deletions

View file

@ -43,7 +43,7 @@ func gzipParse(c *Controller) ([]gzip.Config, error) {
return configs, c.ArgErr()
}
for _, e := range exts {
if !strings.HasPrefix(e, ".") && 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)

View file

@ -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)

View file

@ -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.

View file

@ -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) {