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

Accept data: URLs #607

Closed
wants to merge 1 commit into from
Closed

Accept data: URLs #607

wants to merge 1 commit into from

Conversation

kdau
Copy link
Contributor

@kdau kdau commented May 8, 2021

Browsers have supported data: URLs in the fetch API for some time now. node-fetch will support them as well in its upcoming v3. The fetch API is the simplest and most reliable way to extract files from data: URLs.

Adding this support precludes a future "data:" matching prefix. This change should not break any existing HTTP(S) matchers, but since the "data:" scheme was previously stripped from URLs passed to matchers, this change will break any existing matchers for data: URLs that were full-string, "begin:", front-anchored regex/glob, or otherwise assumed that the "data:" scheme would be absent.

I did not include support for blob: URLs since they are opaque, less feasible to meaningfully test, and not supported by node-fetch.

@kdau
Copy link
Contributor Author

kdau commented May 8, 2021

To clarify about existing data: URL matchers, here's what mine looks like. It is not front-anchored and so would not break, but it only deals with Base64-encoded data (which is adequate for my use case).

fetchMock.get (/;base64,/, async (url) => nodeFetchActual (`data:${url}`));

@wheresrhys
Copy link
Owner

Thanks for working on this, and sorry for the very slow response. I'll pull it into fetch-mock@10

@wheresrhys wheresrhys closed this Jun 15, 2024
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