Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing content type header for assets to metro server. #953

Conversation

aleqsio
Copy link
Contributor

@aleqsio aleqsio commented Mar 21, 2023

Summary

I'm a maintainer of expo-image on the web platform.
To support rendering svg assets by passing the URI to the <img> src prop, it's necessary for the asset url to return the correct content type.

The solution follows the code described in this issue, and was tested to work and allow using SVG assets on web in an expected way.

Fixes #394.

Test plan

SVG returned as text without the patch in this PR:
image

SVG rendered correctly on asset URL after applying the patch:
image

Expected content type:
image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 21, 2023
@aleqsio
Copy link
Contributor Author

aleqsio commented Mar 21, 2023

@motiz88 Sorry for reopening the PR, github codespaces UI removed the branch instead of updating it with recent changes 😕
This is same as #951, but I've removed the redundant line and added requested tests.

@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@robhogan merged this pull request in 75b3da4.

@aleqsio aleqsio deleted the codespace-aleqsio-ideal-palm-tree-wx6vj66r66h9wqr branch March 22, 2023 12:43
facebook-github-bot pushed a commit that referenced this pull request Mar 31, 2023
Summary:
This PR relates to PR #953 and adds the `Content-Length` property when loading assets.

While this isn't mandatory for the apps, it's extremely useful for some debugging possibilities. At Expo, we are working on debugging improvements through Chrome DevTools, and one of these improvements is adding support for the Network inspector.

On the native side, we are limited to what we can infer automatically. One of these limitations is intercepting response bodies. We can't intercept these response bodies if it's larger than 1mb, and because of that, we rely on the `Content-Length` header to communicate the size of the response.

Pull Request resolved: #961

Test Plan:
<img width="1312" alt="image" src="https://user-images.githubusercontent.com/1203991/228896070-61c4c3a4-578f-472a-b6e8-cfe7b2b8e624.png">

I can provide a repository to try this debugger, if it's necessary. You can also test this change by manually loading an existing asset (e.g. `http://localhost/assets/icon.png?platform=android`) and check the response headers in the same debugger.

Reviewed By: robhogan

Differential Revision: D44544314

Pulled By: huntie

fbshipit-source-id: 72da30b0822077e1dc5556a809bed5a67359595e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content-Type not set
3 participants