Send gzip requests with clj-http

462 views Asked by At

How do I send a gzipped request using the dakrone/clj-http client? So far I have:

(http/post <<REDACTED>>
           {:body (->> <<REDACTED>>
                       cheshire.core/generate-string
                       .getBytes
                       clj-http.util/gzip)
            :content-type "application/json"
            :content-encoding "gzip"
            :as :json})

But elasticsearch (the server in my case) is giving 500 errors Illegal character ((CTRL-CHAR, code 31)): only regular white space.

Any ideas?

2

There are 2 answers

1
Svante On

I guess that you need to enable HTTP compression on the server, e. g. in the Elasticsearch config:

http.compression: true 
0
Tianxiang Xiong On

:content-encoding is not a recognized keyword for clj-http. Try :header {"Content-Encoding" "gzip"} instead.