nodeprovider/content/http_provider.rs
1use flowrlib::errors::*;
2use flowrlib::provider::Provider;
3
4pub struct HttpProvider;
5
6impl Provider for HttpProvider {
7 fn resolve_url(&self, url_str: &str, _default_filename: &str, _extensions: &[&str]) -> Result<(String, Option<String>)> {
8/* let url = Url::parse(url_str)
9 .chain_err(|| format!("Could not convert '{}' to valid Url", url_str))?;
10 if url.path().ends_with('/') {
11 info!("'{}' is a directory, so attempting to find context file in it", url);
12 Ok((HttpProvider::find_default_file(&url_str).unwrap(), None))
13 } else {
14 Ok((url.to_string(), None))
15 }
16 */
17 Ok((url_str.into(), None))
18 }
19
20 fn get_contents(&self, _url: &str) -> Result<Vec<u8>> {
21 /*
22 let mut opts = RequestInit::new();
23 opts.method("GET");
24 opts.mode(RequestMode::Cors);
25
26 let request = Request::new_with_str_and_init(
27 "https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master",
28 &opts,
29 )
30 .unwrap();
31
32 request
33 .headers()
34 .set("Accept", "application/vnd.github.v3+json")
35 .unwrap();
36
37 let window = web_sys::window().unwrap();
38 let request_promise = window.fetch_with_request(&request);
39
40 let future = JsFuture::from(request_promise)
41 .and_then(|resp_value| {
42 // `resp_value` is a `Response` object.
43 assert!(resp_value.is_instance_of::<Response>());
44 let resp: Response = resp_value.dyn_into().unwrap();
45 resp.json()
46 })
47 .and_then(|json_value: Promise| {
48 // Convert this other `Promise` into a rust `Future`.
49 JsFuture::from(json_value)
50 })
51 .and_then(|json| {
52 // Use serde to parse the JSON into a struct.
53 let branch_info: Branch = json.into_serde().unwrap();
54
55 // Send the `Branch` struct back to JS as an `Object`.
56 future::ok(JsValue::from_serde(&branch_info).unwrap())
57 });
58 */
59 Ok(Vec::from("hello"))
60 }
61}
62
63impl HttpProvider {
64 /*
65 Passed a path to a directory, it searches for the first file it can find fitting the pattern
66 "context.*", for known file extensions
67 */
68// fn find_default_file(_url: &str) -> Result<String, String> {
69// Err("Not implemented yet".to_string())
70// }
71}