signalapp / Signal-Desktop

A private messenger for Windows, macOS, and Linux.
https://signal.org/download
GNU Affero General Public License v3.0
14.68k stars 2.68k forks source link

Load `og:image` preview even if Content-Length header is missing #7046

Open der-eismann opened 1 month ago

der-eismann commented 1 month ago

First time contributor checklist:

Contributor checklist:

Description

Fixes #6645. As mentioned in the issue already, a lot of major CDNs (e.g. Amazon's CloudFront) omit the Content-Length header in some cases like when compression is enabled. This means that a lot of preview images cannot be loaded on desktop, but load without any issues on the mobile apps, which is confusing for users.

I changed the behavior to not fail when the header is missing. To still keep it safe I moved the Content-Type check in front of it and added a second one checking the actual size of the returned body before loading the image.

Tested with product pages of the shop I work with, previously the image wouldn't load at all, now it's displayed nicely in the chat. I also added a test to see if the second check was working as expected to still bail on huge images. I tested it on Fedora Linux 40 but no other devices.

screenshot-20241010-104432 (Hidden URLs since they are from an internal staging environment)