diff options
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/request.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/request.go | 53 |
1 files changed, 4 insertions, 49 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/request.go b/vendor/gopkg.in/olivere/elastic.v5/request.go index da5a7216e..87d191965 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/request.go @@ -6,7 +6,6 @@ package elastic import ( "bytes" - "compress/gzip" "encoding/json" "io" "io/ioutil" @@ -35,21 +34,13 @@ func (r *Request) SetBasicAuth(username, password string) { ((*http.Request)(r)).SetBasicAuth(username, password) } -// SetBody encodes the body in the request. Optionally, it performs GZIP compression. -func (r *Request) SetBody(body interface{}, gzipCompress bool) error { +// SetBody encodes the body in the request. +func (r *Request) SetBody(body interface{}) error { switch b := body.(type) { case string: - if gzipCompress { - return r.setBodyGzip(b) - } else { - return r.setBodyString(b) - } + return r.setBodyString(b) default: - if gzipCompress { - return r.setBodyGzip(body) - } else { - return r.setBodyJson(body) - } + return r.setBodyJson(body) } } @@ -69,42 +60,6 @@ func (r *Request) setBodyString(body string) error { return r.setBodyReader(strings.NewReader(body)) } -// setBodyGzip gzip's the body. It accepts both strings and structs as body. -// The latter will be encoded via json.Marshal. -func (r *Request) setBodyGzip(body interface{}) error { - switch b := body.(type) { - case string: - buf := new(bytes.Buffer) - w := gzip.NewWriter(buf) - if _, err := w.Write([]byte(b)); err != nil { - return err - } - if err := w.Close(); err != nil { - return err - } - r.Header.Add("Content-Encoding", "gzip") - r.Header.Add("Vary", "Accept-Encoding") - return r.setBodyReader(bytes.NewReader(buf.Bytes())) - default: - data, err := json.Marshal(b) - if err != nil { - return err - } - buf := new(bytes.Buffer) - w := gzip.NewWriter(buf) - if _, err := w.Write(data); err != nil { - return err - } - if err := w.Close(); err != nil { - return err - } - r.Header.Add("Content-Encoding", "gzip") - r.Header.Add("Vary", "Accept-Encoding") - r.Header.Set("Content-Type", "application/json") - return r.setBodyReader(bytes.NewReader(buf.Bytes())) - } -} - // setBodyReader writes the body from an io.Reader. func (r *Request) setBodyReader(body io.Reader) error { rc, ok := body.(io.ReadCloser) |