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
a44d59f1
Commit
a44d59f1
authored
Dec 09, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ioutil.Discard instead for unneeded bytes.
parent
23631cfa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
8 deletions
+5
-8
middleware/gzip/gzip.go
middleware/gzip/gzip.go
+4
-7
middleware/gzip/response_filter.go
middleware/gzip/response_filter.go
+1
-1
No files found.
middleware/gzip/gzip.go
View file @
a44d59f1
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
package
gzip
package
gzip
import
(
import
(
"bytes"
"compress/gzip"
"compress/gzip"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -49,12 +49,9 @@ outer:
...
@@ -49,12 +49,9 @@ outer:
r
.
Header
.
Del
(
"Accept-Encoding"
)
r
.
Header
.
Del
(
"Accept-Encoding"
)
// gzipWriter modifies underlying writer at init,
// gzipWriter modifies underlying writer at init,
// use a
buff
er instead to leave ResponseWriter in
// use a
discard writ
er instead to leave ResponseWriter in
// original form.
// original form.
var
buf
=
&
bytes
.
Buffer
{}
gzipWriter
,
err
:=
newWriter
(
c
,
ioutil
.
Discard
)
defer
buf
.
Reset
()
gzipWriter
,
err
:=
newWriter
(
c
,
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
// should not happen
// should not happen
return
http
.
StatusInternalServerError
,
err
return
http
.
StatusInternalServerError
,
err
...
@@ -65,7 +62,7 @@ outer:
...
@@ -65,7 +62,7 @@ outer:
var
rw
http
.
ResponseWriter
var
rw
http
.
ResponseWriter
// if no response filter is used
// if no response filter is used
if
len
(
c
.
ResponseFilters
)
==
0
{
if
len
(
c
.
ResponseFilters
)
==
0
{
// replace
buff
er with ResponseWriter
// replace
discard writ
er with ResponseWriter
gzipWriter
.
Reset
(
w
)
gzipWriter
.
Reset
(
w
)
rw
=
gz
rw
=
gz
}
else
{
}
else
{
...
...
middleware/gzip/response_filter.go
View file @
a44d59f1
...
@@ -52,7 +52,7 @@ func (r *ResponseFilterWriter) WriteHeader(code int) {
...
@@ -52,7 +52,7 @@ func (r *ResponseFilterWriter) WriteHeader(code int) {
}
}
if
r
.
shouldCompress
{
if
r
.
shouldCompress
{
// replace
buff
er with ResponseWriter
// replace
discard writ
er with ResponseWriter
if
gzWriter
,
ok
:=
r
.
gzipResponseWriter
.
Writer
.
(
*
gzip
.
Writer
);
ok
{
if
gzWriter
,
ok
:=
r
.
gzipResponseWriter
.
Writer
.
(
*
gzip
.
Writer
);
ok
{
gzWriter
.
Reset
(
r
.
ResponseWriter
)
gzWriter
.
Reset
(
r
.
ResponseWriter
)
}
}
...
...
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