Browse Source

Dont compress when the header contains a Websocket upgrade (#12)

Schmitt 8 years ago
parent
commit
ce345a8285
1 changed files with 4 additions and 1 deletions
  1. 4 1
      gzip.go

+ 4 - 1
gzip.go

@@ -62,9 +62,12 @@ func (g *gzipWriter) Write(data []byte) (int, error) {
 }
 }
 
 
 func shouldCompress(req *http.Request) bool {
 func shouldCompress(req *http.Request) bool {
-	if !strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") {
+	if !strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") ||
+		strings.Contains(req.Header.Get("Connection"), "Upgrade") {
+
 		return false
 		return false
 	}
 	}
+
 	extension := filepath.Ext(req.URL.Path)
 	extension := filepath.Ext(req.URL.Path)
 	if len(extension) < 4 { // fast path
 	if len(extension) < 4 { // fast path
 		return true
 		return true