Skip to content

feat: add transparent gzip/deflate decompression (#155) - #817

Merged
benoitc merged 1 commit into
masterfrom
fix/155-auto-decompress
Jan 20, 2026
Merged

benoitc merged 1 commit into
masterfrom
fix/155-auto-decompress

Conversation

@benoitc

@benoitc benoitc commented Jan 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add {auto_decompress, true} option for automatic response body decompression (fixes Add transparent Content-Encoding: gzip/deflate support #155)
  • When enabled, adds Accept-Encoding: gzip, deflate header to requests
  • Automatically decompresses response body based on Content-Encoding header
  • Supports gzip, deflate, and x-gzip encodings
  • Graceful fallback for uncompressed or unknown encodings

Usage

{ok, Status, Headers, Body} = hackney:request(get, URL, [], [], 
    [{with_body, true}, {auto_decompress, true}])

Changes

  • include/hackney_lib.hrl: Add content_encoding field to hparser record
  • src/hackney_http.erl: Parse Content-Encoding header
  • src/hackney.erl: Add Accept-Encoding header when auto_decompress is set
  • src/hackney_conn.erl: Add decompression in read_full_body
  • test/hackney_decompress_tests.erl: Tests for gzip/deflate decompression

Add support for automatic decompression of gzip and deflate encoded
HTTP responses via the `auto_decompress` option.

When enabled:
- Adds `Accept-Encoding: gzip, deflate` header to requests
- Automatically decompresses response body based on Content-Encoding
- Supports gzip, deflate, and x-gzip encodings
- Graceful fallback for uncompressed or unknown encodings

Usage:
  hackney:request(get, URL, [], [], [{with_body, true}, {auto_decompress, true}])

The decompression is performed when reading the full body via body/1.
Streaming responses (stream_body) are not affected by this option.
@benoitc
benoitc merged commit 06608b6 into master Jan 20, 2026
5 checks passed
@benoitc
benoitc deleted the fix/155-auto-decompress branch January 20, 2026 18:07
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.

Add transparent Content-Encoding: gzip/deflate support

1 participant