-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add fetch local file #2152
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 fetch local file #2152
Conversation
Cool. This repo is like a wish fairy. I briefly looked into the wikipedia article about file uri scheme and it said that syntax like And what about other protocols like ftp? Just bringing in ideas. |
FTP may be added in another PR. Concerning all the schemes i'll dig into. |
Hi, I have a quick question: As fetch is a asynchronous function, why is a synchronous open file function being used? |
Fair point. In fact the open is Synchronous but the reading is still async. Having the open as Sync is like building the header of the http request synchronously (as we do now). It would be interesting to measure the impact of both. BTW, i'll move it to async. |
@phil294 about HOST part of the URI it's not used at the moment because we are considering fetching a local file and not getting it throught the network. It can be a possibility but i think the implementation would change a bit. Also i've added a link to the RFC. Maybe a special section of the documentation may be added. For example the RFC is not very clear about the handling of relative path but a lot of interpreters are allowing it. ATM i think it fits the need. See RFC8089 : https://tools.ietf.org/html/rfc8089 |
js/fetch.ts
Outdated
) { | ||
return new Response(404, [], 0); | ||
} else { | ||
return new Response(500, [], 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any metadata associated with this error? If so, would it make sense to JSON-encode it and put it as the body of this response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as i know the errorkind notfound is just an enum for the error code. The only error i think would be not found or permission error. But just put a standard json encoded object like {message:"file not found"}
would be interesting. If so someone can give me a hint how to pass it to the Response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would calling JSON.stringify(e)
be a possibility (with try catch)?
I've rebased the PR and added missing types for eslint. @kevinkassimo suggested to use |
If you're satisfied with the using |
So i figured out how to add Is it revelant to add a feature that without the read permission we may be allowed to read |
I would be very happy to have fetch for local files, but this patch has gone stale. I apologize for not getting it in sooner, @zekth. But in the interest of clearing up old PRs, I'm going to close this. |
This fixes #2150
I have 2 questions:
Here : https://github.com/denoland/deno/compare/master...zekth:fetch_local?expand=1#diff-cee0e68f0ac7840274b5171cf4df9dbeR410 i need to handle the
content-type
but it's in deno_std atm. Any idea? Also, how could i get the content-lenght?