Fetchable dapps (#1949)

* Fetching dapp from github.

* Unpacking dapp

* Removing hardcodes

* Proper Host validation

* Randomizing paths

* Splitting into files

* Serving donwloaded apps from different path

* Extracting URLHint to separate module

* Whitespace and docs
This commit is contained in:
Tomasz Drwięga
2016-08-18 12:19:09 +02:00
committed by Gav Wood
parent 57dbdaada9
commit 0620a03e56
17 changed files with 941 additions and 22 deletions

View File

@@ -16,13 +16,12 @@
use DAPPS_DOMAIN;
use hyper::server;
use hyper::{server, header};
use hyper::net::HttpStream;
use jsonrpc_http_server::{is_host_header_valid};
use handlers::ContentHandler;
pub fn is_valid(request: &server::Request<HttpStream>, bind_address: &str, endpoints: Vec<String>) -> bool {
let mut endpoints = endpoints.into_iter()
.map(|endpoint| format!("{}{}", endpoint, DAPPS_DOMAIN))
@@ -31,7 +30,13 @@ pub fn is_valid(request: &server::Request<HttpStream>, bind_address: &str, endpo
endpoints.push(bind_address.replace("127.0.0.1", "localhost").into());
endpoints.push(bind_address.into());
is_host_header_valid(request, &endpoints)
let header_valid = is_host_header_valid(request, &endpoints);
match (header_valid, request.headers().get::<header::Host>()) {
(true, _) => true,
(_, Some(host)) => host.hostname.ends_with(DAPPS_DOMAIN),
_ => false,
}
}
pub fn host_invalid_response() -> Box<server::Handler<HttpStream> + Send> {