diff --git a/dapps/src/apps/fetcher.rs b/dapps/src/apps/fetcher.rs index 85eef8f73..041064121 100644 --- a/dapps/src/apps/fetcher.rs +++ b/dapps/src/apps/fetcher.rs @@ -151,7 +151,6 @@ impl ContentFetcher { let (handler, fetch_control) = ContentFetcherHandler::new( dapp.url(), control, - path.using_dapps_domains, DappInstaller { id: content_id.clone(), dapps_path: self.dapps_path.clone(), @@ -167,7 +166,6 @@ impl ContentFetcher { let (handler, fetch_control) = ContentFetcherHandler::new( content.url, control, - path.using_dapps_domains, ContentInstaller { id: content_id.clone(), mime: content.mime, diff --git a/dapps/src/apps/mod.rs b/dapps/src/apps/mod.rs index a7b97d37c..11919d6d2 100644 --- a/dapps/src/apps/mod.rs +++ b/dapps/src/apps/mod.rs @@ -33,14 +33,6 @@ pub const RPC_PATH : &'static str = "rpc"; pub const API_PATH : &'static str = "api"; pub const UTILS_PATH : &'static str = "parity-utils"; -pub fn redirection_address(using_dapps_domains: bool, app_id: &str) -> String { - if using_dapps_domains { - format!("http://{}{}/", app_id, DAPPS_DOMAIN) - } else { - format!("/{}/", app_id) - } -} - pub fn utils() -> Box { Box::new(PageEndpoint::with_prefix(parity_ui::App::default(), UTILS_PATH.to_owned())) } diff --git a/dapps/src/handlers/fetch.rs b/dapps/src/handlers/fetch.rs index e5acfc50b..1a0221bff 100644 --- a/dapps/src/handlers/fetch.rs +++ b/dapps/src/handlers/fetch.rs @@ -22,14 +22,14 @@ use std::sync::{mpsc, Arc}; use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{Instant, Duration}; use util::Mutex; +use url::Url; use fetch::{Client, Fetch, FetchResult}; use hyper::{server, Decoder, Encoder, Next, Method, Control}; use hyper::net::HttpStream; use hyper::status::StatusCode; -use handlers::{ContentHandler, Redirection}; -use apps::redirection_address; +use handlers::{ContentHandler, Redirection, extract_url}; use page::LocalPageEndpoint; const FETCH_TIMEOUT: u64 = 30; @@ -136,8 +136,8 @@ pub struct ContentFetcherHandler { control: Option, status: FetchState, client: Option, - using_dapps_domains: bool, installer: H, + request_url: Option, embeddable_at: Option, } @@ -156,7 +156,6 @@ impl ContentFetcherHandler { pub fn new( url: String, control: Control, - using_dapps_domains: bool, handler: H, embeddable_at: Option, ) -> (Self, Arc) { @@ -168,8 +167,8 @@ impl ContentFetcherHandler { control: Some(control), client: Some(client), status: FetchState::NotStarted(url), - using_dapps_domains: using_dapps_domains, installer: handler, + request_url: None, embeddable_at: embeddable_at, }; @@ -193,6 +192,7 @@ impl ContentFetcherHandler { impl server::Handler for ContentFetcherHandler { fn on_request(&mut self, request: server::Request) -> Next { + self.request_url = extract_url(&request); let status = if let FetchState::NotStarted(ref url) = self.status { Some(match *request.method() { // Start fetching content @@ -267,8 +267,10 @@ impl server::Handler for ContentFetcherHandler< )) }, Ok((id, result)) => { - let address = redirection_address(self.using_dapps_domains, &id); - FetchState::Done(id, result, Redirection::new(&address)) + let url: String = self.request_url.take() + .map(|url| url.raw.into_string()) + .expect("Request URL always read in on_request; qed"); + FetchState::Done(id, result, Redirection::new(&url)) }, }; // Remove temporary zip file