Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
4588812d
Commit
4588812d
authored
Jul 06, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gzip: Fix wildcard extension bug.
parent
7dbe4228
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
3 deletions
+15
-3
config/setup/gzip.go
config/setup/gzip.go
+1
-1
config/setup/gzip_test.go
config/setup/gzip_test.go
+5
-0
middleware/gzip/filter.go
middleware/gzip/filter.go
+2
-2
middleware/gzip/filter_test.go
middleware/gzip/filter_test.go
+7
-0
No files found.
config/setup/gzip.go
View file @
4588812d
...
@@ -43,7 +43,7 @@ func gzipParse(c *Controller) ([]gzip.Config, error) {
...
@@ -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
)
...
...
config/setup/gzip_test.go
View file @
4588812d
...
@@ -68,6 +68,11 @@ func TestGzip(t *testing.T) {
...
@@ -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
)
...
...
middleware/gzip/filter.go
View file @
4588812d
...
@@ -33,14 +33,14 @@ type ExtFilter struct {
...
@@ -33,14 +33,14 @@ type ExtFilter struct {
}
}
// extWildCard is the wildcard for extensions.
// extWildCard is the wildcard for extensions.
const
e
xtWildCard
=
"*"
const
E
xtWildCard
=
"*"
// 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
(
e
xtWildCard
)
||
e
.
Exts
.
Contains
(
ext
)
return
e
.
Exts
.
Contains
(
E
xtWildCard
)
||
e
.
Exts
.
Contains
(
ext
)
}
}
// PathFilter is Filter for request path.
// PathFilter is Filter for request path.
...
...
middleware/gzip/filter_test.go
View file @
4588812d
...
@@ -73,6 +73,13 @@ func TestExtFilter(t *testing.T) {
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment