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
Łukasz Nowak
caddy
Commits
a946d65f
Commit
a946d65f
authored
Dec 18, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oops. Tests.
parent
f04ff063
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
5 deletions
+8
-5
middleware/gzip/gzip_test.go
middleware/gzip/gzip_test.go
+0
-1
middleware/gzip/response_filter.go
middleware/gzip/response_filter.go
+8
-3
middleware/gzip/response_filter_test.go
middleware/gzip/response_filter_test.go
+0
-1
No files found.
middleware/gzip/gzip_test.go
View file @
a946d65f
...
...
@@ -80,7 +80,6 @@ func TestGzipHandler(t *testing.T) {
func
nextFunc
(
shouldGzip
bool
)
middleware
.
Handler
{
return
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
w
.
WriteHeader
(
200
)
w
.
Write
([]
byte
(
"test"
))
if
shouldGzip
{
if
r
.
Header
.
Get
(
"Accept-Encoding"
)
!=
""
{
...
...
middleware/gzip/response_filter.go
View file @
a946d65f
...
...
@@ -31,6 +31,7 @@ func (l LengthFilter) ShouldCompress(w http.ResponseWriter) bool {
type
ResponseFilterWriter
struct
{
filters
[]
ResponseFilter
shouldCompress
bool
statusCodeWritten
bool
*
gzipResponseWriter
}
...
...
@@ -39,7 +40,7 @@ func NewResponseFilterWriter(filters []ResponseFilter, gz *gzipResponseWriter) *
return
&
ResponseFilterWriter
{
filters
:
filters
,
gzipResponseWriter
:
gz
}
}
// Write wraps underlying Write method and compresses if filters
// Write wraps underlying Write
Header
method and compresses if filters
// are satisfied.
func
(
r
*
ResponseFilterWriter
)
WriteHeader
(
code
int
)
{
// Determine if compression should be used or not.
...
...
@@ -62,11 +63,15 @@ func (r *ResponseFilterWriter) WriteHeader(code int) {
}
else
{
r
.
ResponseWriter
.
WriteHeader
(
code
)
}
r
.
statusCodeWritten
=
true
}
// Write wraps underlying Write method and compresses if filters
// are satisfied
func
(
r
*
ResponseFilterWriter
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
if
!
r
.
statusCodeWritten
{
r
.
WriteHeader
(
http
.
StatusOK
)
}
if
r
.
shouldCompress
{
return
r
.
gzipResponseWriter
.
Write
(
b
)
}
...
...
middleware/gzip/response_filter_test.go
View file @
a946d65f
...
...
@@ -63,7 +63,6 @@ func TestResponseFilterWriter(t *testing.T) {
for
i
,
ts
:=
range
tests
{
server
.
Next
=
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
w
.
Header
()
.
Set
(
"Content-Length"
,
fmt
.
Sprint
(
len
(
ts
.
body
)))
w
.
WriteHeader
(
200
)
w
.
Write
([]
byte
(
ts
.
body
))
return
200
,
nil
})
...
...
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