From f16ee58559afccd90c459f6d5d09533b83e78db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Bi=C5=82as?= Date: Thu, 4 Oct 2018 11:10:13 +0200 Subject: [PATCH] Simplify compressed response handling This commit simplifies gzip compressed response handling. Godoc clearly says that by default http.Transport will add 'Accept-Encoding: gzip' to a Request and transparently decode the response if a 'Content-Encoding: gzip' header is present. See https://golang.org/src/net/http/transport.go#L181 Therefore it is only necessary to add "enable_http_compression=1" HTTP query parameter to Clickhouse server requests. --- conn.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/conn.go b/conn.go index d74eb67..4630c1f 100644 --- a/conn.go +++ b/conn.go @@ -1,7 +1,6 @@ package clickhouse import ( - "compress/gzip" "context" "database/sql" "database/sql/driver" @@ -213,15 +212,7 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) (io.ReadCloser, return nil, err } - respBody := resp.Body - if resp.Header.Get("Content-Encoding") == "gzip" { - respBody, err = gzip.NewReader(respBody) - if err != nil { - return nil, err - } - } - - return respBody, nil + return resp.Body, nil } func (c *conn) buildRequest(query string, params []driver.Value, readonly bool) (*http.Request, error) { @@ -246,9 +237,6 @@ func (c *conn) buildRequest(query string, params []driver.Value, readonly bool) p, _ := c.user.Password() req.SetBasicAuth(c.user.Username(), p) } - if c.useGzipCompression { - req.Header.Set("Accept-Encoding", "gzip") - } return req, err }