Skip to content
Snippets Groups Projects
Unverified Commit 5f1d7077 authored by Will McCutchen's avatar Will McCutchen Committed by GitHub
Browse files

Merge pull request #3 from na--/deflate-fixes

Fix deflate encoded responses
parents 1a922f18 6dda7bfb
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,8 @@ package httpbin ...@@ -2,8 +2,8 @@ package httpbin
import ( import (
"bytes" "bytes"
"compress/flate"
"compress/gzip" "compress/gzip"
"compress/zlib"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
...@@ -109,7 +109,7 @@ func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request) { ...@@ -109,7 +109,7 @@ func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request) {
body, _ := json.Marshal(resp) body, _ := json.Marshal(resp)
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
w2, _ := flate.NewWriter(buf, flate.DefaultCompression) w2 := zlib.NewWriter(buf)
w2.Write(body) w2.Write(body)
w2.Close() w2.Close()
......
...@@ -3,8 +3,8 @@ package httpbin ...@@ -3,8 +3,8 @@ package httpbin
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"compress/flate"
"compress/gzip" "compress/gzip"
"compress/zlib"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -1261,7 +1261,10 @@ func TestDeflate(t *testing.T) { ...@@ -1261,7 +1261,10 @@ func TestDeflate(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
reader := flate.NewReader(w.Body) reader, err := zlib.NewReader(w.Body)
if err != nil {
t.Fatal(err)
}
body, err := ioutil.ReadAll(reader) body, err := ioutil.ReadAll(reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment