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

feat: use file extensions from collection names for MIME guessing #25

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

Frando
Copy link
Member

@Frando Frando commented Jan 26, 2024

I was trying to serve a website (HTML and CSS) from an iroh collection with the iroh-gateway example. It works, but CSS is not applied to the page because the gateway serves CSS files with text/plain, which makes the browser ignore it.

The MIME guesser currently only uses the blob data to guess the mime type (via mime_classifier. This is insufficient in many cases (e.g. all text files will be text/plain).

This PR changes this so that for blobs served through collections, the extension of the filename from the collection metadata is used to guess the MIME type. If the file has no or an unknown extension, it falls back to the mime_classifier.

With this change, we can serve websites. At least basic static sites.

@Frando Frando changed the title feat: use file extensions from collection names for mime guessing feat: use file extensions from collection names for MIME guessing Jan 26, 2024
@Frando Frando force-pushed the gateway/mime-from-name branch from 1c07585 to 9209561 Compare January 26, 2024 14:33
Copy link
Contributor

@rklaehn rklaehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. So the extension takes precedent over the content?

@rklaehn rklaehn merged commit 22b93e4 into main Jan 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants