Skip to content

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

Closed
wants to merge 12 commits into from
Closed

Add fetch local file #2152

wants to merge 12 commits into from

Conversation

zekth
Copy link
Contributor

@zekth zekth commented Apr 19, 2019

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?

@phil294
Copy link

phil294 commented Apr 19, 2019

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 file://localhost/./myfile.txt is valid too etc.

And what about other protocols like ftp?

Just bringing in ideas.

@zekth
Copy link
Contributor Author

zekth commented Apr 19, 2019

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 file://localhost/./myfile.txt is valid too etc.

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.

@harrysarson
Copy link

Hi, I have a quick question:

As fetch is a asynchronous function, why is a synchronous open file function being used?

@zekth
Copy link
Contributor Author

zekth commented Apr 20, 2019

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.

@zekth
Copy link
Contributor Author

zekth commented Apr 20, 2019

@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);
Copy link
Contributor

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?

Copy link
Contributor Author

@zekth zekth Apr 20, 2019

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?

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)?

@zekth
Copy link
Contributor Author

zekth commented May 11, 2019

I've rebased the PR and added missing types for eslint.
Also for the return of the fetch in case of issue i've added this:
https://github.com/denoland/deno/pull/2152/files#diff-cee0e68f0ac7840274b5171cf4df9dbeR425

@kevinkassimo suggested to use /dev/null for unix and NUL for windows. Is there a way i open those filedescriptors and get the rid of it? any clue about this to land this PR?

@zekth
Copy link
Contributor Author

zekth commented May 12, 2019

If you're satisfied with the using open('NUL') i think we can land it.

@zekth
Copy link
Contributor Author

zekth commented May 12, 2019

So i figured out how to add /dev/null and NUL reading. But the problem is when permission is not allowed we get a Deno.ErrorKind.PermissionDenied the problem is by this way i can't return a HTTP 403 error code of the fetch local.

Is it revelant to add a feature that without the read permission we may be allowed to read NUL and /dev/null ? (in this case it's usefull)

@ry
Copy link
Member

ry commented Jul 23, 2019

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.

@ry ry closed this Jul 23, 2019
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.

fetch() a local file
5 participants