aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

Support gzip encoding in SdkHttpFullRequest

Open dblock opened this issue 2 years ago • 0 comments

Describe the feature

I'd like to be able to pass an uncompressed stream into SdkHttpFullRequest.builder() and have it do the compression for me. This is because I also want it to support chunked requests, and do Sigv4 signing "out of the box" for all these combinations.

String payload = "{\"test\": \"val\"}";

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
gzipOutputStream.write(payload.getBytes("UTF-8"));
gzipOutputStream.close();

SdkHttpFullRequest request = SdkHttpFullRequest.builder()
                .method(SdkHttpMethod.POST)
                .uri(URI.create(ENDPOINT + "/index_name/type_name/document_id"))
                .appendHeader("Content-Type", "application/json")
                .appendHeader("Content-Encoding", "gzip")
                .contentStreamProvider(() -> new ByteArrayInputStream(outputStream.toByteArray()))
                .build();

I found https://github.com/aws/aws-sdk-java-v2/issues/131 and https://github.com/aws/aws-sdk-java-v2/issues/866 but I don't think they are quite as specific as this.

Use Case

Coming from https://github.com/dblock/aws-sdk-sigv4-demo where we attempt to make signed, compressed and chunked requests to Amazon OpenSearch.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS Java SDK version used

2.17.224

JDK version used

11

Operating System and version

MacOS

dblock avatar Jul 08 '22 16:07 dblock