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
553d76da
Commit
553d76da
authored
Jul 05, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #179 from abiosoft/master
gzip: Const for wildcard extension (and added test)
parents
9467dbdd
d4f0ac23
Changes
4
Show 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 @
553d76da
...
...
@@ -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
)
...
...
config/setup/gzip_test.go
View file @
553d76da
...
...
@@ -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
)
...
...
middleware/gzip/filter.go
View file @
553d76da
...
...
@@ -33,14 +33,14 @@ type ExtFilter struct {
}
// extWildCard is the wildcard for extensions.
const
e
xtWildCard
=
"*"
const
E
xtWildCard
=
"*"
// 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
(
e
xtWildCard
)
||
e
.
Exts
.
Contains
(
ext
)
return
e
.
Exts
.
Contains
(
E
xtWildCard
)
||
e
.
Exts
.
Contains
(
ext
)
}
// PathFilter is Filter for request path.
...
...
middleware/gzip/filter_test.go
View file @
553d76da
...
...
@@ -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
)
{
...
...
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