-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Guess extensions on extension not provided #859
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
Changes from 7 commits
c6a2413
bffb412
699822b
09739fb
469771e
c4f5adb
02fbf23
9da5589
b9d1ccc
eb95e04
c211eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,17 @@ | ||
| // Copyright 2018 the Deno authors. All rights reserved. MIT license. | ||
|
|
||
| use errors::DenoResult; | ||
| use errors::{DenoError, DenoResult}; | ||
| use futures::stream::Concat2; | ||
| use futures::{Async, Future}; | ||
| use tokio_util; | ||
|
|
||
| use futures::Future; | ||
| use futures::Stream; | ||
| use hyper; | ||
| use hyper::client::Client; | ||
|
kevinkassimo marked this conversation as resolved.
|
||
| use hyper::client::HttpConnector; | ||
| use hyper::Uri; | ||
| use hyper_rustls; | ||
| use std::io; | ||
|
|
||
| type Connector = hyper_rustls::HttpsConnector<HttpConnector>; | ||
|
|
||
|
|
@@ -26,16 +28,51 @@ pub fn get_client() -> Client<Connector, hyper::Body> { | |
| Client::builder().build(c) | ||
| } | ||
|
|
||
| struct FetchedBodyFuture { | ||
| body: Concat2<hyper::Body>, | ||
| status: hyper::StatusCode, | ||
| } | ||
|
|
||
| struct FetchedBody { | ||
| body: hyper::Chunk, | ||
| status: hyper::StatusCode, | ||
| } | ||
|
|
||
| impl Future for FetchedBodyFuture { | ||
| type Item = FetchedBody; | ||
| type Error = hyper::Error; | ||
| fn poll(&mut self) -> Result<Async<FetchedBody>, hyper::Error> { | ||
| match self.body.poll()? { | ||
| Async::Ready(body) => Ok(Async::Ready(FetchedBody { | ||
| body, | ||
| status: self.status.clone(), | ||
| })), | ||
| Async::NotReady => Ok(Async::NotReady), | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| // The CodeFetch message is used to load HTTP javascript resources and expects a | ||
| // synchronous response, this utility method supports that. | ||
| pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> { | ||
| let url = module_name.parse::<Uri>().unwrap(); | ||
| let client = get_client(); | ||
| let future = client | ||
| .get(url) | ||
| .and_then(|response| response.into_body().concat2()); | ||
| let body = tokio_util::block_on(future)?; | ||
| Ok(String::from_utf8(body.to_vec()).unwrap()) | ||
| let fetch_future = client.get(url).and_then(|response| { | ||
| let status = response.status(); | ||
| FetchedBodyFuture { | ||
| body: response.into_body().concat2(), | ||
| status, | ||
| } | ||
| }); | ||
|
|
||
| let fetch_result = tokio_util::block_on(fetch_future)?; | ||
| if !fetch_result.status.is_success() { | ||
| return Err(DenoError::from(io::Error::new( | ||
| io::ErrorKind::NotFound, | ||
| format!("cannot load from '{}'", module_name), | ||
| ))); | ||
| } | ||
| Ok(String::from_utf8(fetch_result.body.to_vec()).unwrap()) | ||
| } | ||
|
|
||
| /* TODO(ry) Re-enabled this test. Disabling to work around bug in #782. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { isTSFile, printHello, phNoExt } from "./subdir/mod3"; | ||
| console.log(isTSFile); | ||
| console.log(printHello); | ||
| console.log(phNoExt); | ||
|
|
||
| import { isMod4 } from "./subdir/mod4"; | ||
| console.log(isMod4); | ||
|
|
||
| import { printHello as ph } from "http://localhost:4545/tests/subdir/mod2"; | ||
| console.log(ph); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Downloading http://localhost:4545/tests/subdir/mod2.ts | ||
| Downloading http://localhost:4545/tests/subdir/print_hello.ts | ||
| true | ||
| [Function: printHello] | ||
| [Function: printHello] | ||
| true | ||
| [Function: printHello] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import "./non-existent"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]deno/tests/error_006_import_ext_failure.ts" | ||
| at maybeError (deno/js/errors.ts:[WILDCARD]) | ||
| at maybeThrowError (deno/js/errors.ts:[WILDCARD]) | ||
| at sendSync (deno/js/dispatch.ts:[WILDCARD]) | ||
| at Object.codeFetch (deno/js/os.ts:[WILDCARD]) | ||
| at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD]) | ||
| at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD]) | ||
| at moduleNames.map.name (deno/js/compiler.ts:[WILDCARD]) | ||
| at Array.map (<anonymous>) | ||
| at DenoCompiler.resolveModuleNames (deno/js/compiler.ts:[WILDCARD]) | ||
| at Object.compilerHost.resolveModuleNames (deno/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const isTSFile = false; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const isTSFile = true; | ||
| export { printHello } from "./print_hello.ts"; | ||
| export { printHello as phNoExt } from "./print_hello"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const isMod4 = true; |
Uh oh!
There was an error while loading. Please reload this page.