Load og:image
preview even if Content-Length header is missing
#7046
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First time contributor checklist:
Contributor checklist:
main
branchnpm run ready
run passes successfully (more about tests here)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.
(Hidden URLs since they are from an internal staging environment)