Skip to content

Gzip compression/inflation handling - #338

Open
spenserw wants to merge 6 commits into
opensearch-project:mainfrom
spenserw:spenserw/gzip-compression
Open

Gzip compression/inflation handling#338
spenserw wants to merge 6 commits into
opensearch-project:mainfrom
spenserw:spenserw/gzip-compression

Conversation

@spenserw

Copy link
Copy Markdown

Description

As described in the client initialization doc comments:

  1. Applies Gzip compression to requests when the compression flag is passed to the client
  2. Automatically inflates responses that have been Gzip encoded
  3. Correctly sets the default state of the compression option

Issues Resolved

Closes #337

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@spenserw
spenserw force-pushed the spenserw/gzip-compression branch from a3e7f04 to 45d6c31 Compare August 18, 2026 20:47

@gaobinlong gaobinlong left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @spenserw , awesome work, left some comments, and change log is needed I think.

end

def compress_request(body)
io = StringIO.new

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringIO.new creates a UTF-8 buffer, the GzipWriter is told to use ASCII-8BIT (binary) encoding, but the underlying StringIO buffer remains UTF-8, so when gzip writes binary bytes into it, io.string returns a UTF-8-tagged string containing binary data — which can blow up downstream when something tries to interpret or concatenate it as text. Consider using binary-mode buffer by io = StringIO.new(''.b) ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice catch, wouldn't want any nasty surprises in the future... updated


def compress_request(body)
io = StringIO.new
gzip_writer = if RUBY_ENCODING

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUBY_ENCODING always be true since we are now using 3.x?

@spenserw spenserw Aug 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed there was some legacy behavior being protected, but yes I see the 3.x requirement now that I look.. cleaned this up and also removed it from the inflation path, too

@spenserw
spenserw requested a review from gaobinlong August 21, 2026 22:40
Signed-off-by: Spenser Williams <spenser@w2cs.com>
Signed-off-by: Spenser Williams <spenser@w2cs.com>
Signed-off-by: Spenser Williams <spenser@w2cs.com>
Signed-off-by: Spenser Williams <spenser@w2cs.com>
Signed-off-by: Spenser Williams <spenser@w2cs.com>
@spenserw
spenserw force-pushed the spenserw/gzip-compression branch from e4655e1 to c8e6ea4 Compare August 21, 2026 22:41
Signed-off-by: Spenser Williams <spenser@w2cs.com>
@spenserw

Copy link
Copy Markdown
Author

Updated changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Request & response compression (Gzip) not behaving as advertised

3 participants