Skip to content

Commit

Permalink
Simplify compressed response handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maciej committed Oct 4, 2018
1 parent 6dafbca commit 8a7cca9
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions conn.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package clickhouse

import (
"compress/gzip"
"context"
"database/sql"
"database/sql/driver"
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down

0 comments on commit 8a7cca9

Please sign in to comment.