Files
AFFiNE-Mirror/packages
Luis Freixial 2365c36557 fix(server): stop forwarding Accept-Encoding in worker link-preview/image-proxy (#15560)
## Description

Self-hosted AFFiNE's `/api/worker/link-preview` and
`/api/worker/image-proxy` endpoints forward the requesting browser's
`Accept-Encoding` header to whatever URL they fetch (`cloneHeader()`),
but the underlying native `safeFetch` never decompresses the response
before parsing it. Sites that gzip/brotli-compress their HTML (GitHub
does, for any non-trivially-sized repo page) end up handing AFFiNE
compressed bytes, which the HTMLRewriter meta-tag scraper silently reads
as nothing. The result: link preview cards render with no image, title,
or description.

**Fix:** drop `Accept-Encoding` from the headers forwarded in
`cloneHeader()`, so upstream requests are implicitly identity-encoded
and the response body stays uncompressed for the parsing that follows.

**Before**
<img width="641" height="335" alt="image"
src="https://github.com/user-attachments/assets/8ec8a925-6a1f-422a-9cb0-5e1687a5f75e"
/>

**After**
<img width="659" height="323" alt="image"
src="https://github.com/user-attachments/assets/c35002b5-43c1-4f8b-a4c2-20028f1e453a"
/>


## Checklist

- [x] I have signed the [AFFiNE Contributor License
Agreement](https://cla-assistant.io/toeverything/AFFiNE) — required
before merge; the `license/cla` check must be green ([how it
works](https://github.com/toeverything/AFFiNE/blob/canary/docs/BUILDING.md#sign-the-cla-first))
- [x] The PR targets the `canary` branch and its title follows
[Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests are added or updated where it makes sense
- [x] `yarn lint` and `yarn typecheck` pass locally
- [x] If the PR code includes AI-generated edits, I have carefully
reviewed it to ensure that the scope of the PR is consistent with what
is claimed in the title and description, and that there are no redundant
or invalid implementations.
- [x] I agree that maintainers may close the PR without discussion if
they consider the code quality to be too low.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Prevented `Accept-Encoding` headers from being forwarded when
processing worker link-preview and image-proxy requests.
* Improved request handling to avoid passing client compression
preferences to external fetch targets.

* **Tests**
* Added end-to-end coverage confirming that `Accept-Encoding` is
excluded from forwarded requests.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-03 11:51:57 +08:00
..