-
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
Guess extensions on extension not provided #859
Conversation
eaa2195
to
ebd46d2
Compare
28c792d
to
f4c9d6e
Compare
f4c9d6e
to
469771e
Compare
src/http.rs
Outdated
format!("cannot load from '{}'", module_name), | ||
))?; | ||
} | ||
let body = tokio_util::block_on(response.into_body().concat2())?; |
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.
Maybe it doesn't matter but this could be done using only one block_on
. It would be nice to have a test showing we get NotFound error when trying to hit 404 url.
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.
So I have somehow combined into a single block_on
, but had to explicitly implement Future for a struct holding Concat2
and StatusCode
(to implement using enum that either holds body or and error seems more problematic)
(I started to use Rust only very recently, so this might not be a very good solution from the viewpoint of elegance. Would like to learn about better alternatives!)
btw a NotFound test is added
src/http.rs
Outdated
Async::NotReady => Ok(Async::NotReady), | ||
} | ||
} | ||
} |
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.
This seems not so much related to the current problem - although something like this may be necessary at some point when we address fetch body streaming. I'd rather you not add this here. Either go back to using block_on
twice or find some other way of doing this. Have you tried using map()
?
@ry So I have somehow forcefully used If this still looks pretty bad, I could either shift back to the original 2 block_on implementation, or probably let someone more familiar with Rust to take over this PR and address this very last piece. Aside: looks like async/await syntax is recently introduced to Rust |
742d680
to
70270a0
Compare
70270a0
to
b9d1ccc
Compare
.concat2() | ||
.map(|body| String::from_utf8(body.to_vec()).unwrap()) | ||
.map_err(|err| DenoError::from(err)), | ||
) |
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.
I tried to do this more simply myself but couldn't. I think this is correct. Rust is annoyingly painful at times.
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.
Yeah... I found threads complaining similar stuff this morning, and supposedly these issues could be better addressed with the currently experimental async-await syntax
src/deno_dir.rs
Outdated
}); | ||
}; | ||
let default_attempt = use_extension(""); | ||
if let Ok(_) = default_attempt { |
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.
If no need to use the value in Ok
, would it be better to use with is_some()
?
if default_attempt.is_some() {
return default_attempt;
}
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.
Good point
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.
BTW should be
if default_attempt.is_ok() {
return default_attempt;
}
Thanks!
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.
Ah, yes! Thanks for catching the typo :P
e553617
to
c211eb7
Compare
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.
LGTM - Thanks Kevin!
- Improve fetch headers (denoland#853) - Add deno.truncate (denoland#805) - Add copyFile/copyFileSync (denoland#863) - Limit depth of output in console.log for nested objects, and add console.dir (denoland#826) - Guess extensions on extension not provided (denoland#859) - Renames: deno.platform -> deno.platform.os deno.arch -> deno.platform.arch - Upgrade TS to 3.0.3 - Add readDirSync(), readDir() - Add support for TCP servers and clients. (denoland#884) Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
- Improve fetch headers (#853) - Add deno.truncate (#805) - Add copyFile/copyFileSync (#863) - Limit depth of output in console.log for nested objects, and add console.dir (#826) - Guess extensions on extension not provided (#859) - Renames: deno.platform -> deno.platform.os deno.arch -> deno.platform.arch - Upgrade TS to 3.0.3 - Add readDirSync(), readDir() - Add support for TCP servers and clients. (#884) Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
Trying to close #857
Guess .ts -> Guess .js -> Give up
Added tests in both
tests/
anddeno_dir.rs
.(Hope I have not missed something...)