Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Redirect content to the same address as requested #3133

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dapps/src/apps/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ impl<R: URLHint> ContentFetcher<R> {
let (handler, fetch_control) = ContentFetcherHandler::new(
dapp.url(),
control,
path.using_dapps_domains,
DappInstaller {
id: content_id.clone(),
dapps_path: self.dapps_path.clone(),
Expand All @@ -167,7 +166,6 @@ impl<R: URLHint> ContentFetcher<R> {
let (handler, fetch_control) = ContentFetcherHandler::new(
content.url,
control,
path.using_dapps_domains,
ContentInstaller {
id: content_id.clone(),
mime: content.mime,
Expand Down
8 changes: 0 additions & 8 deletions dapps/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Endpoint> {
Box::new(PageEndpoint::with_prefix(parity_ui::App::default(), UTILS_PATH.to_owned()))
}
Expand Down
16 changes: 9 additions & 7 deletions dapps/src/handlers/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,8 +136,8 @@ pub struct ContentFetcherHandler<H: ContentValidator> {
control: Option<Control>,
status: FetchState,
client: Option<Client>,
using_dapps_domains: bool,
installer: H,
request_url: Option<Url>,
embeddable_at: Option<u16>,
}

Expand All @@ -156,7 +156,6 @@ impl<H: ContentValidator> ContentFetcherHandler<H> {
pub fn new(
url: String,
control: Control,
using_dapps_domains: bool,
handler: H,
embeddable_at: Option<u16>,
) -> (Self, Arc<FetchControl>) {
Expand All @@ -168,8 +167,8 @@ impl<H: ContentValidator> ContentFetcherHandler<H> {
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,
};

Expand All @@ -193,6 +192,7 @@ impl<H: ContentValidator> ContentFetcherHandler<H> {

impl<H: ContentValidator> server::Handler<HttpStream> for ContentFetcherHandler<H> {
fn on_request(&mut self, request: server::Request<HttpStream>) -> Next {
self.request_url = extract_url(&request);
let status = if let FetchState::NotStarted(ref url) = self.status {
Some(match *request.method() {
// Start fetching content
Expand Down Expand Up @@ -267,8 +267,10 @@ impl<H: ContentValidator> server::Handler<HttpStream> 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
Expand Down