-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fetch() a local file #2150
Comments
Seems reasonable to me. |
I will push a PR to fix this. |
is the behavior for fetch with file: urls standardized? |
Browsers cannot fetch local files in general, that would be a big security issue. Thats why the spec also only ever speaks about network or data/blob/about URLs. https://fetch.spec.whatwg.org/#url node does not implement fetch at all. |
@Janpot I don't think so. Also see the comments below from Much thought have gone into this issue, for sure. I'd like to condense the most important reasons I believe URLs of file scheme should not be implemented in node-fetch. I would of course be thankful if @bitinn or @zkat would like to weigh in and offer their opinions here as well. 1. Accessing the local filesystem eases security breaches.Take @jimmywarting's (admittedly anecdotal and contrived) use case:
Really, I cannot believe many people are using node-fetch as a proxy (I might be wrong of course, but IMO there are many much better ways to create a proxy in Node.js). But I find it easy to imagine people who are using a URL from an untrusted source (the network for example) and just plug it into @stevenvachon proposed using an option to allow file URL scheme. That may solve this issue, but see my response below. 2. There is no recognized standards for interpretation of file-scheme URLs.As outlined in sindresorhus/got#227 filed by @stevenvachon, WHATWG's Fetch Standard offers no discussion of how file URL schemes should be interpreted on different platforms. In fact, in the PR adding documentation for Node.js Now that file URL scheme is supported officially in Node.js, I foresee a de-facto standard being established at least in the Node.js community. But then in less than a month when Node.js 8.0.0 is released, users can use 3. There is no precedent for support of file-scheme URLs in Node.js community.None of the most popular URL-to-response libraries I can think of in under a minute do not support file-scheme URLs:
4. Browser
|
fetch just create an unnecessary layer of complexity. if you intent to read some local file use the fs directly. |
That's news to me. Yes, Chrome disallows |
And Chrome has the
I don't think this is a good reason to disallow it in deno. Deno's fetch shouldn't and doesn't behave exactly like browser fetch because in Deno the code is running on a machine that trusts it. That's why we don't need to worry about CORs header stuff, for example.
What about relative URLs? They're allowed in the browser, but disallowed in Deno. I think that's quite sane and unsurprising. Similarly, it it wouldn't be very surprising if the browser disallows
But this is Deno! Viva la revolution! :) Caveat to all of this is that I'm very new to Deno - so I basically have no idea what I'm talking about. Separate, but tangentially related to this discussion: The |
Should this be supported or just stick to the |
fetch supporting local files is still desirable... it is easier to write isomorphic code that way. |
Please don’t make Wasn’t it “If it’s just nice, don’t do it.”, or something along those lines what Ryan said? Also there is the Native File System API coming out. |
Supporting Assuming Native File System API get more traction, we would support that as well. |
I'm not sure why keeping this open is offending you. Extending a capability of a browser standard to support situations that make sense for a server runtime is synergistic with the goals of Deno. We don't want to do it trivially or carelessly, but it has and can be done. |
Can I suggest that fetch support for file:// URLs should be enabled, that it should respect the permissions given by —allow-read when accessing file:// URLs, and that the fetch implementation should support range requests on files. Thanks! |
Ref https://fetch.spec.whatwg.org/#scheme-fetch.
|
The core team discussed this semi-recently, and the decision was to not make a decision about this right now. |
When using deno deploy we can fetch local files so unless there's some black magic behind this, it would make senses that it works on vanilla deno too I can't seem to find a way to make an app capable of reading loading a local json that is compatible for both deploy and deno, because the first one don't have |
deployctl uses https://deno.land/x/file_fetch to support fetching local files. |
Closes #11925 Closes #2150 Co-authored-by: Bert Belder <[email protected]>
Coming from https://stackoverflow.com/q/51941064/3779853
Any plans to support
await fetch("file:///./input.txt")
? Like Jeremy, this is the first thing I'd intiuitively try to read a local file, given deno's philosophy of browser-like methods.The text was updated successfully, but these errors were encountered: