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
12cd2d52
Commit
12cd2d52
authored
Jan 12, 2016
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gzip: Fix for wrong content-type when templates is used.
parent
8a6c778c
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
217 additions
and
4 deletions
+217
-4
middleware/gzip/gzip.go
middleware/gzip/gzip.go
+3
-3
middleware/gzip/gzip_test.go
middleware/gzip/gzip_test.go
+15
-1
middleware/gzip/testdata/test.txt
middleware/gzip/testdata/test.txt
+199
-0
No files found.
middleware/gzip/gzip.go
View file @
12cd2d52
...
...
@@ -121,12 +121,12 @@ func (w *gzipResponseWriter) WriteHeader(code int) {
// Write wraps the underlying Write method to do compression.
func
(
w
*
gzipResponseWriter
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
if
!
w
.
statusCodeWritten
{
w
.
WriteHeader
(
http
.
StatusOK
)
}
if
w
.
Header
()
.
Get
(
"Content-Type"
)
==
""
{
w
.
Header
()
.
Set
(
"Content-Type"
,
http
.
DetectContentType
(
b
))
}
if
!
w
.
statusCodeWritten
{
w
.
WriteHeader
(
http
.
StatusOK
)
}
n
,
err
:=
w
.
Writer
.
Write
(
b
)
return
n
,
err
}
middleware/gzip/gzip_test.go
View file @
12cd2d52
...
...
@@ -2,8 +2,10 @@ package gzip
import
(
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/mholt/caddy/middleware"
...
...
@@ -80,7 +82,16 @@ func TestGzipHandler(t *testing.T) {
func
nextFunc
(
shouldGzip
bool
)
middleware
.
Handler
{
return
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
w
.
Write
([]
byte
(
"test"
))
// write a relatively large text file
b
,
err
:=
ioutil
.
ReadFile
(
"testdata/test.txt"
)
if
err
!=
nil
{
return
500
,
err
}
if
_
,
err
:=
w
.
Write
(
b
);
err
!=
nil
{
return
500
,
err
}
if
shouldGzip
{
if
r
.
Header
.
Get
(
"Accept-Encoding"
)
!=
""
{
return
0
,
fmt
.
Errorf
(
"Accept-Encoding header not expected"
)
...
...
@@ -94,6 +105,9 @@ func nextFunc(shouldGzip bool) middleware.Handler {
if
_
,
ok
:=
w
.
(
*
gzipResponseWriter
);
!
ok
{
return
0
,
fmt
.
Errorf
(
"ResponseWriter should be gzipResponseWriter, found %T"
,
w
)
}
if
strings
.
Contains
(
w
.
Header
()
.
Get
(
"Content-Type"
),
"application/x-gzip"
)
{
return
0
,
fmt
.
Errorf
(
"Content type should not be gzip."
)
}
return
0
,
nil
}
if
r
.
Header
.
Get
(
"Accept-Encoding"
)
==
""
{
...
...
middleware/gzip/testdata/test.txt
0 → 100644
View file @
12cd2d52
This diff is collapsed.
Click to expand it.
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