Skip to content

Commit

Permalink
Only compress if client sets Accept-Encoding header (fixes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Aug 4, 2016
1 parent ea66afc commit 1adb697
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions simplehttp2server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ func main() {
if !*disableGzip {
oldfs := fs
fs = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Encoding", "gzip")
grw := GzipResponseWriter{gzip.NewWriter(w), w}
oldfs.ServeHTTP(grw, r)
grw.WriteCloser.Close()
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip")
grw := GzipResponseWriter{gzip.NewWriter(w), w}
defer grw.WriteCloser.Close()
w = grw
}
oldfs.ServeHTTP(w, r)
})
}

Expand Down

2 comments on commit 1adb697

@default-writer
Copy link

@default-writer default-writer commented on 1adb697 Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, is this GitHub repo is down? Should i use google/go repo? Are you going to enhance project to being production ready? I need it to know because it is sufficient for me to make a decision do i need to start R&D cycle for HTTP/2.0 for the future features of the web site or just throw this dream away and just keep it up with 1.1

@surma
Copy link
Contributor Author

@surma surma commented on 1adb697 Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplehttp2server is never going to be a production web server, it’s for local development only (as said in the README). If you want HTTP/2 in production, use nginx, Apache, nghttp or any of the others. Take a look at my blogpost.

Please sign in to comment.