-
Notifications
You must be signed in to change notification settings - Fork 104
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: customizeable content type parsing in @helia/verified-fetch #422
Comments
Providing a way to pass custom content type sniffer sounds sensible, but will be a very niche feature request if your default is something comprehenbsive like I think the question we could ask is when is content-type relevant:
That is to say, I think it is sensible to either:
|
My feeling is that if we don't need to do content type sniffing then let's not do it. If we need to do it, we should do the minimum required (e.g. just support detecting a small subset of content types) and provide an extension mechanism for more comprehensive detection. Given that we're billing this as There are valid use-cases for content detection though (e.g. service worker gateway) so allowing users to configure a mime type sniffer if they need it seems like a good compromise. |
Mostly agree with @lidel and @achingbrain, though I don't have a strong inclination either way. If we don't include magic-byte sniffing by default, it should be as easy as possible to configure so it works smoothly in service workers. |
Sounds good. Ill get a PR out today that will not do content-type unless passed a function for it |
* adds `contentTypeParser` function to createVerifiedFetch options & implements it. * renamed `getStreamAndContentType` to `getStreamFromAsyncIterable` that now returns a stream with the firstChunk seen, so we can pass it to the `contentTypeParser` function. * updates tests in packages/verified-fetch & packages/interop * updates packageDocumentation with example Related #416 Fixes #422 --------- Co-authored-by: achingbrain <alex@achingbrain.net>
* adds `contentTypeParser` function to createVerifiedFetch options & implements it. * renamed `getStreamAndContentType` to `getStreamFromAsyncIterable` that now returns a stream with the firstChunk seen, so we can pass it to the `contentTypeParser` function. * updates tests in packages/verified-fetch & packages/interop * updates packageDocumentation with example Related ipfs/helia#416 Fixes ipfs/helia#422 --------- Co-authored-by: achingbrain <alex@achingbrain.net>
Discussed with @achingbrain due to #416
Goals
Initial design idea
Remove dependency on
mime-types
, don't depend onfile-type
some interface such as
createVerifiedFetch(helia, { contentTypeParser: (bytes) => myFn})
and we provide a defaultcontentTypeParser
that determines content type for the below list only.We would pass the
contentTypeParser
function the first block of bytes we receive; and because most of our blocks are 1MB or below, we can safely assume the majority of content types users need to recognize can be determined by looking at those first 1MB of bytes.If content-type is not a recognized type from the below list, we do not set it (allows browser sniffing).
Supported content types
References
cc @achingbrain @aschmahmann @lidel @2color
The text was updated successfully, but these errors were encountered: