asynchttpPost Support Content-Encoding?

Hello,

I am currently writing a driver to send data to a api service and to optimize the sending process I would like to compress the post request.

I have tried specifying the necessary headers and compressed the content but it looks like the under the hood method asynchttpPost is not supporting the content encoding:

  Map postParams = [
        uri: "https://SAS",
        requestContentType: 'application/json',
        contentType: 'application/json',
        headers: ['Content-Encoding':'gzip'],
        body : string2gzip(jsonObject.toString())
  ]
  asynchttpPost('logResponse', postParams)

@bravenel
Do you guys know if this is something that could be added OOTB with a new parameter?

@gopher.ny | @bravenel
Any news or details on this or insights

requestContentType should do it. I'm going to run some tests.

Edit: yeah, requestContentType works. I've added an endpoint to test what goes out, /hub/test/noop. It produces log entries like the ones below and will be a part of next build.

3 Likes

Great! this will he helpful for orher integrations. I'll give it a try once released

@gopher.ny was this par of the beta built 2.3.4.132? I tried it an I still get the same error

Yes, /hub/test/noop is a part of the 2.3.4.132 build.

Just in case others are interested, this is the code for the string2gzip function

String string2gzip(String s){
  ByteArrayOutputStream bos = new ByteArrayOutputStream()
  java.util.zip.GZIPOutputStream gzip = new java.util.zip.GZIPOutputStream(bos)
  gzip.write(s.getBytes('UTF-8'))
  gzip.close()
  byte[] gzipBytes = bos.toByteArray()
  bos.close()
  return gzipBytes.encodeBase64()
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.