0

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?

bm1729
  • 2,315
  • 3
  • 21
  • 30
  • FWIW your call looks correct according to its [test](https://github.com/dakrone/clj-http/blob/70df5add2a565a87d2ac79b39e90f777999babc0/test/clj_http/test/client_test.clj#L608). Does the request work without gzip? – Taylor Wood Sep 21 '18 at 14:27
  • Yep, removing the .getBytes, clj-http.util/gzip and :content-encoding "gzip" gives me a successful request. – bm1729 Sep 21 '18 at 14:36
  • Have you tried like in the test? Use `clj-http.util/utf8-bytes` to be explicit with the encoding you want or add it to `.getBytes` (but then use `->` instead of `->>`) – cfrick Sep 24 '18 at 13:55

1 Answers1

0

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

http.compression: true 
Svante
  • 50,694
  • 11
  • 78
  • 122
  • I'm able to send gzipped requests with curl. I think the problem is with my use of the library or my gzipping code. – bm1729 Sep 24 '18 at 08:30