## Issue
Closes#5800
## Change
`Utils.readBytes(String url)` sends `Accept-Encoding: gzip, deflate` but
reads the
response body as a **raw** `InputStream`. `HttpURLConnection` only
decompresses gzip
transparently when it adds the `Accept-Encoding` header itself; because
the header is set
explicitly here, the JDK disables transparent decoding and returns the
body exactly as
sent. So when a server responds with `Content-Encoding: gzip` (nginx,
CDNs, S3, most image
hosts), `readBytes` returns the still-compressed bytes.
`readBytes(url)` is used to inline remote images/PDFs as base64 for
several model
integrations (Ollama, Bedrock, Vertex/Gemini image mappers,
`Image`/`PdfFile` helpers), so
a gzip-serving host silently produced a corrupted payload.
This PR decodes the response stream according to the `Content-Encoding`
header via a small
private helper:
- `gzip` / `x-gzip` → `GZIPInputStream`
- `deflate` → `InflaterInputStream` (zlib, per RFC 9110)
- anything else / no header → the raw stream, unchanged
No new dependencies. The uncompressed happy path is byte-for-byte
unchanged (same stream,
same copy loop). The wrapper is created inside the existing
try-with-resources, so closing
it closes the underlying HTTP stream.
Added `/gzip_endpoint` and `/deflate_endpoint` cases to
`UtilsTest.read_bytes` that serve a
compressed body with the matching `Content-Encoding` header and assert
the decoded bytes;
both fail against the previous behaviour.
## General checklist
- [X] There are no breaking changes (API, behaviour) — uncompressed
responses are unchanged
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases — decoded
gzip/deflate plus the existing raw/uncompressed and HTTP-error paths
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green — `langchain4j-core`
`UtilsTest` (46/46) and `spotless:check` pass
- [ ] I have manually run all the unit and integration tests in the core
and main modules, and they are all green
- [ ] I have added/updated the documentation — n/a, internal utility, no
public API or behaviour visible in docs
- [ ] I have added an example in the examples repo (only for "big"
features) — n/a
- [ ] I have added/updated Spring Boot starter(s) (if applicable) — n/a
---------
Co-authored-by: Timur Rakhmatullin <174210871+TimurRakhmatullin86@users.noreply.github.com>
Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>