Skip to content
Snippets Groups Projects
Unverified Commit 6dda7bfb authored by Nedyalko Andreev's avatar Nedyalko Andreev
Browse files

Fix deflate encoded responses

RFC 2616 (HTTP/1.1) says in the "3.5 Content Codings" [1] section about deflate:

    The "zlib" format defined in RFC 1950 [31] in combination with the "deflate" compression mechanism described in RFC 1951 [29].

The zlib package [2] from Go's standard library imlpements RFC 1950 and it also uses[3] the flate package internally, which implements RFC 1951 [4]

[1] https://tools.ietf.org/html/rfc2616#section-3.5
[2] https://golang.org/pkg/compress/zlib/#pkg-overview
[3] https://golang.org/src/compress/zlib/writer.go#L15
[4] https://golang.org/pkg/compress/flate/#pkg-overview
parent 8e86068c
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,8 @@ package httpbin
import (
"bytes"
"compress/flate"
"compress/gzip"
"compress/zlib"
"encoding/json"
"fmt"
"math/rand"
......@@ -109,7 +109,7 @@ func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request) {
body, _ := json.Marshal(resp)
buf := &bytes.Buffer{}
w2, _ := flate.NewWriter(buf, flate.DefaultCompression)
w2 := zlib.NewWriter(buf)
w2.Write(body)
w2.Close()
......
......@@ -3,8 +3,8 @@ package httpbin
import (
"bufio"
"bytes"
"compress/flate"
"compress/gzip"
"compress/zlib"
"encoding/json"
"fmt"
"io/ioutil"
......@@ -1261,7 +1261,10 @@ func TestDeflate(t *testing.T) {
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)
if err != nil {
t.Fatal(err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment