2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-04-07 12:10:26 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Router implementation
|
2017-04-03 10:27:37 +02:00
|
|
|
//! Dispatch requests to proper application.
|
2016-04-07 12:10:26 +02:00
|
|
|
|
2017-04-05 11:37:45 +02:00
|
|
|
use std::sync::Arc;
|
2016-05-13 18:40:20 +02:00
|
|
|
use std::collections::HashMap;
|
2017-03-22 07:02:14 +01:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
use futures::future;
|
|
|
|
use hyper::{self, header, Uri};
|
2017-04-03 10:27:37 +02:00
|
|
|
use jsonrpc_http_server as http;
|
2017-03-22 07:02:14 +01:00
|
|
|
|
2017-05-24 12:24:07 +02:00
|
|
|
use apps;
|
2016-12-22 18:26:39 +01:00
|
|
|
use apps::fetcher::Fetcher;
|
2017-10-05 12:35:01 +02:00
|
|
|
use endpoint::{self, Endpoint, EndpointPath};
|
2017-08-09 19:06:40 +02:00
|
|
|
use Endpoints;
|
2017-05-24 12:24:07 +02:00
|
|
|
use handlers;
|
2017-07-04 16:04:09 +02:00
|
|
|
use Embeddable;
|
2016-04-07 18:22:53 +02:00
|
|
|
|
2016-05-13 18:40:20 +02:00
|
|
|
/// Special endpoints are accessible on every domain (every dapp)
|
|
|
|
#[derive(Debug, PartialEq, Hash, Eq)]
|
|
|
|
pub enum SpecialEndpoint {
|
2016-05-12 17:13:26 +02:00
|
|
|
Rpc,
|
|
|
|
Api,
|
2016-05-13 18:40:20 +02:00
|
|
|
Utils,
|
2017-05-24 12:24:07 +02:00
|
|
|
Home,
|
2016-05-16 20:22:19 +02:00
|
|
|
None,
|
2016-05-12 17:13:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
enum Response {
|
|
|
|
Some(endpoint::Response),
|
|
|
|
None(hyper::Request),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An endpoint router.
|
|
|
|
/// Dispatches the request to particular Endpoint by requested uri/path.
|
2017-04-05 11:37:45 +02:00
|
|
|
pub struct Router {
|
2017-05-24 12:24:07 +02:00
|
|
|
endpoints: Option<Endpoints>,
|
2017-04-05 11:37:45 +02:00
|
|
|
fetch: Arc<Fetcher>,
|
2017-04-03 10:27:37 +02:00
|
|
|
special: HashMap<SpecialEndpoint, Option<Box<Endpoint>>>,
|
2017-07-04 16:04:09 +02:00
|
|
|
embeddable_on: Embeddable,
|
2017-05-24 12:24:07 +02:00
|
|
|
dapps_domain: String,
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-09 19:06:40 +02:00
|
|
|
impl Router {
|
2017-10-05 12:35:01 +02:00
|
|
|
fn resolve_request(&self, req: hyper::Request, refresh_dapps: bool) -> (bool, Response) {
|
2016-09-01 10:16:04 +02:00
|
|
|
// Choose proper handler depending on path / domain
|
2017-10-05 12:35:01 +02:00
|
|
|
let endpoint = extract_endpoint(req.uri(), req.headers().get(), &self.dapps_domain);
|
|
|
|
let referer = extract_referer_endpoint(&req, &self.dapps_domain);
|
2016-09-01 10:16:04 +02:00
|
|
|
let is_utils = endpoint.1 == SpecialEndpoint::Utils;
|
2016-12-27 11:15:02 +01:00
|
|
|
let is_get_request = *req.method() == hyper::Method::Get;
|
2017-05-24 12:24:07 +02:00
|
|
|
let is_head_request = *req.method() == hyper::Method::Head;
|
2017-08-09 19:06:40 +02:00
|
|
|
let has_dapp = |dapp: &str| self.endpoints
|
|
|
|
.as_ref()
|
|
|
|
.map_or(false, |endpoints| endpoints.endpoints.read().contains_key(dapp));
|
2016-09-01 10:16:04 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
trace!(target: "dapps", "Routing request to {:?}. Details: {:?}", req.uri(), req);
|
|
|
|
debug!(target: "dapps", "Handling endpoint request: {:?}, referer: {:?}", endpoint, referer);
|
2017-08-09 19:06:40 +02:00
|
|
|
|
|
|
|
(is_utils, match (endpoint.0, endpoint.1, referer) {
|
2016-12-27 11:15:02 +01:00
|
|
|
// Handle invalid web requests that we can recover from
|
2017-10-05 12:35:01 +02:00
|
|
|
(ref path, SpecialEndpoint::None, Some(ref referer))
|
2017-01-16 10:49:27 +01:00
|
|
|
if referer.app_id == apps::WEB_PATH
|
2017-08-09 19:06:40 +02:00
|
|
|
&& has_dapp(apps::WEB_PATH)
|
2016-12-27 11:15:02 +01:00
|
|
|
&& !is_web_endpoint(path)
|
|
|
|
=>
|
|
|
|
{
|
2017-10-05 12:35:01 +02:00
|
|
|
let token = referer.app_params.get(0).map(String::as_str).unwrap_or("");
|
|
|
|
let requested = req.uri().path();
|
|
|
|
let query = req.uri().query().map_or_else(String::new, |query| format!("?{}", query));
|
|
|
|
let redirect_url = format!("/{}/{}{}{}", apps::WEB_PATH, token, requested, query);
|
|
|
|
trace!(target: "dapps", "Redirecting to correct web request: {:?}", redirect_url);
|
|
|
|
Response::Some(Box::new(future::ok(
|
|
|
|
handlers::Redirection::new(redirect_url).into()
|
|
|
|
)))
|
2016-12-27 11:15:02 +01:00
|
|
|
},
|
2016-07-20 12:34:17 +02:00
|
|
|
// First check special endpoints
|
2016-12-27 11:15:02 +01:00
|
|
|
(ref path, ref endpoint, _) if self.special.contains_key(endpoint) => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to special endpoint.");
|
2017-10-05 12:35:01 +02:00
|
|
|
let special = self.special.get(endpoint).expect("special known to contain key; qed");
|
|
|
|
match *special {
|
|
|
|
Some(ref special) => Response::Some(special.respond(path.clone().unwrap_or_default(), req)),
|
|
|
|
None => Response::None(req),
|
|
|
|
}
|
2016-07-20 12:34:17 +02:00
|
|
|
},
|
|
|
|
// Then delegate to dapp
|
2017-08-09 19:06:40 +02:00
|
|
|
(Some(ref path), _, _) if has_dapp(&path.app_id) => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to local/builtin dapp.");
|
2017-10-05 12:35:01 +02:00
|
|
|
Response::Some(self.endpoints
|
2017-05-24 12:24:07 +02:00
|
|
|
.as_ref()
|
|
|
|
.expect("endpoints known to be set; qed")
|
2017-08-09 19:06:40 +02:00
|
|
|
.endpoints
|
|
|
|
.read()
|
2017-05-24 12:24:07 +02:00
|
|
|
.get(&path.app_id)
|
2016-12-27 11:15:02 +01:00
|
|
|
.expect("endpoints known to contain key; qed")
|
2017-10-05 12:35:01 +02:00
|
|
|
.respond(path.clone(), req))
|
2016-07-20 12:34:17 +02:00
|
|
|
},
|
2016-08-30 16:05:18 +02:00
|
|
|
// Try to resolve and fetch the dapp
|
2016-12-27 11:15:02 +01:00
|
|
|
(Some(ref path), _, _) if self.fetch.contains(&path.app_id) => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to fetchable content.");
|
2017-10-05 12:35:01 +02:00
|
|
|
Response::Some(self.fetch.respond(path.clone(), req))
|
2016-08-18 12:19:09 +02:00
|
|
|
},
|
2017-05-24 12:24:07 +02:00
|
|
|
// 404 for non-existent content (only if serving endpoints and not homepage)
|
|
|
|
(Some(ref path), _, _)
|
|
|
|
if (is_get_request || is_head_request)
|
|
|
|
&& self.endpoints.is_some()
|
|
|
|
&& path.app_id != apps::HOME_PAGE
|
|
|
|
=>
|
|
|
|
{
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to 404.");
|
2017-08-09 19:06:40 +02:00
|
|
|
if refresh_dapps {
|
|
|
|
debug!(target: "dapps", "Refreshing dapps and re-trying.");
|
|
|
|
self.endpoints.as_ref().map(|endpoints| endpoints.refresh_local_dapps());
|
2017-10-05 12:35:01 +02:00
|
|
|
return self.resolve_request(req, false);
|
2017-08-09 19:06:40 +02:00
|
|
|
} else {
|
2017-10-05 12:35:01 +02:00
|
|
|
Response::Some(Box::new(future::ok(handlers::ContentHandler::error(
|
2017-08-09 19:06:40 +02:00
|
|
|
hyper::StatusCode::NotFound,
|
|
|
|
"404 Not Found",
|
|
|
|
"Requested content was not found.",
|
|
|
|
None,
|
|
|
|
self.embeddable_on.clone(),
|
2017-10-05 12:35:01 +02:00
|
|
|
).into())))
|
2017-08-09 19:06:40 +02:00
|
|
|
}
|
2016-07-20 12:34:17 +02:00
|
|
|
},
|
2017-05-24 12:24:07 +02:00
|
|
|
// Any other GET|HEAD requests to home page.
|
|
|
|
_ if (is_get_request || is_head_request) && self.special.contains_key(&SpecialEndpoint::Home) => {
|
2017-10-05 12:35:01 +02:00
|
|
|
let special = self.special.get(&SpecialEndpoint::Home).expect("special known to contain key; qed");
|
|
|
|
match *special {
|
|
|
|
Some(ref special) => {
|
|
|
|
let mut endpoint = EndpointPath::default();
|
|
|
|
endpoint.app_params = req.uri().path().split('/').map(str::to_owned).collect();
|
|
|
|
Response::Some(special.respond(endpoint, req))
|
|
|
|
},
|
|
|
|
None => Response::None(req),
|
|
|
|
}
|
2016-08-30 16:05:18 +02:00
|
|
|
},
|
2016-07-20 12:34:17 +02:00
|
|
|
// RPC by default
|
|
|
|
_ => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to RPC call.");
|
2017-10-05 12:35:01 +02:00
|
|
|
Response::None(req)
|
2016-04-08 15:25:20 +02:00
|
|
|
}
|
2017-08-09 19:06:40 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 14:45:09 +02:00
|
|
|
|
2017-08-09 19:06:40 +02:00
|
|
|
impl http::RequestMiddleware for Router {
|
2017-10-05 12:35:01 +02:00
|
|
|
fn on_request(&self, req: hyper::Request) -> http::RequestMiddlewareAction {
|
2017-08-09 19:06:40 +02:00
|
|
|
let is_origin_set = req.headers().get::<header::Origin>().is_some();
|
2017-10-05 12:35:01 +02:00
|
|
|
let (is_utils, response) = self.resolve_request(req, self.endpoints.is_some());
|
|
|
|
match response {
|
|
|
|
Response::Some(response) => http::RequestMiddlewareAction::Respond {
|
2017-05-24 12:24:07 +02:00
|
|
|
should_validate_hosts: !is_utils,
|
2017-10-05 12:35:01 +02:00
|
|
|
response,
|
2017-04-03 10:27:37 +02:00
|
|
|
},
|
2017-10-05 12:35:01 +02:00
|
|
|
Response::None(request) => http::RequestMiddlewareAction::Proceed {
|
2017-04-03 10:27:37 +02:00
|
|
|
should_continue_on_invalid_cors: !is_origin_set,
|
2017-10-05 12:35:01 +02:00
|
|
|
request,
|
2017-04-03 10:27:37 +02:00
|
|
|
},
|
|
|
|
}
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 11:37:45 +02:00
|
|
|
impl Router {
|
2016-04-08 16:11:58 +02:00
|
|
|
pub fn new(
|
2017-04-05 11:37:45 +02:00
|
|
|
content_fetcher: Arc<Fetcher>,
|
2017-05-24 12:24:07 +02:00
|
|
|
endpoints: Option<Endpoints>,
|
2017-04-03 10:27:37 +02:00
|
|
|
special: HashMap<SpecialEndpoint, Option<Box<Endpoint>>>,
|
2017-07-04 16:04:09 +02:00
|
|
|
embeddable_on: Embeddable,
|
2017-05-24 12:24:07 +02:00
|
|
|
dapps_domain: String,
|
2017-04-03 10:27:37 +02:00
|
|
|
) -> Self {
|
2016-04-07 12:10:26 +02:00
|
|
|
Router {
|
2016-04-14 20:38:48 +02:00
|
|
|
endpoints: endpoints,
|
2016-09-04 23:44:46 +02:00
|
|
|
fetch: content_fetcher,
|
2016-05-13 18:40:20 +02:00
|
|
|
special: special,
|
2017-05-24 12:24:07 +02:00
|
|
|
embeddable_on: embeddable_on,
|
|
|
|
dapps_domain: format!(".{}", dapps_domain),
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 15:05:59 +02:00
|
|
|
}
|
2016-04-07 12:10:26 +02:00
|
|
|
|
2016-12-27 11:15:02 +01:00
|
|
|
fn is_web_endpoint(path: &Option<EndpointPath>) -> bool {
|
|
|
|
match *path {
|
|
|
|
Some(ref path) if path.app_id == apps::WEB_PATH => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn extract_referer_endpoint(req: &hyper::Request, dapps_domain: &str) -> Option<EndpointPath> {
|
2016-12-27 11:15:02 +01:00
|
|
|
let referer = req.headers().get::<header::Referer>();
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
let url = referer.and_then(|referer| referer.parse().ok());
|
2016-12-27 11:15:02 +01:00
|
|
|
url.and_then(|url| {
|
2017-10-05 12:35:01 +02:00
|
|
|
extract_url_referer_endpoint(&url, dapps_domain).or_else(|| {
|
|
|
|
extract_endpoint(&url, None, dapps_domain).0
|
2017-01-16 10:49:27 +01:00
|
|
|
})
|
2016-12-27 11:15:02 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn extract_url_referer_endpoint(url: &Uri, dapps_domain: &str) -> Option<EndpointPath> {
|
|
|
|
let query = url.query();
|
|
|
|
match query {
|
|
|
|
Some(query) if query.starts_with(apps::URL_REFERER) => {
|
|
|
|
let scheme = url.scheme().unwrap_or("http");
|
|
|
|
let host = url.host().unwrap_or("unknown");
|
|
|
|
let port = default_port(url, None);
|
|
|
|
let referer_url = format!("{}://{}:{}/{}", scheme, host, port, &query[apps::URL_REFERER.len()..]);
|
2017-01-16 10:49:27 +01:00
|
|
|
debug!(target: "dapps", "Recovering referer from query parameter: {}", referer_url);
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
if let Some(referer_url) = referer_url.parse().ok() {
|
|
|
|
extract_endpoint(&referer_url, None, dapps_domain).0
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-01-16 10:49:27 +01:00
|
|
|
},
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn extract_endpoint(url: &Uri, extra_host: Option<&header::Host>, dapps_domain: &str) -> (Option<EndpointPath>, SpecialEndpoint) {
|
|
|
|
fn special_endpoint(path: &[&str]) -> SpecialEndpoint {
|
|
|
|
if path.len() <= 1 {
|
2016-05-12 17:13:26 +02:00
|
|
|
return SpecialEndpoint::None;
|
|
|
|
}
|
2016-05-13 18:40:20 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
match path[0].as_ref() {
|
2016-05-13 18:40:20 +02:00
|
|
|
apps::RPC_PATH => SpecialEndpoint::Rpc,
|
|
|
|
apps::API_PATH => SpecialEndpoint::Api,
|
|
|
|
apps::UTILS_PATH => SpecialEndpoint::Utils,
|
2017-05-24 12:24:07 +02:00
|
|
|
apps::HOME_PAGE => SpecialEndpoint::Home,
|
2016-05-12 17:13:26 +02:00
|
|
|
_ => SpecialEndpoint::None,
|
|
|
|
}
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
let port = default_port(url, extra_host.as_ref().and_then(|h| h.port()));
|
|
|
|
let host = url.host().or_else(|| extra_host.as_ref().map(|h| h.hostname()));
|
|
|
|
let query = url.query().map(str::to_owned);
|
|
|
|
let mut path_segments = url.path().split('/').skip(1).collect::<Vec<_>>();
|
|
|
|
trace!(
|
|
|
|
target: "dapps",
|
|
|
|
"Extracting endpoint from: {:?} (dapps: {}). Got host {:?}:{} with path {:?}",
|
|
|
|
url, dapps_domain, host, port, path_segments
|
|
|
|
);
|
|
|
|
match host {
|
|
|
|
Some(host) if host.ends_with(dapps_domain) => {
|
|
|
|
let id = &host[0..(host.len() - dapps_domain.len())];
|
|
|
|
let special = special_endpoint(&path_segments);
|
|
|
|
|
|
|
|
// remove special endpoint id from params
|
|
|
|
if special != SpecialEndpoint::None {
|
|
|
|
path_segments.remove(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
let (app_id, app_params) = if let Some(split) = id.rfind('.') {
|
|
|
|
let (params, id) = id.split_at(split);
|
|
|
|
path_segments.insert(0, params);
|
|
|
|
(id[1..].to_owned(), path_segments)
|
|
|
|
} else {
|
|
|
|
(id.to_owned(), path_segments)
|
|
|
|
};
|
|
|
|
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id,
|
|
|
|
app_params: app_params.into_iter().map(Into::into).collect(),
|
|
|
|
query,
|
|
|
|
host: host.to_owned(),
|
|
|
|
port,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), special)
|
|
|
|
},
|
|
|
|
Some(host) if path_segments.len() > 1 => {
|
|
|
|
let special = special_endpoint(&path_segments);
|
|
|
|
let id = path_segments.remove(0);
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: id.to_owned(),
|
|
|
|
app_params: path_segments.into_iter().map(Into::into).collect(),
|
|
|
|
query,
|
|
|
|
host: host.to_owned(),
|
|
|
|
port,
|
|
|
|
using_dapps_domains: false,
|
|
|
|
}), special)
|
2016-05-12 15:05:59 +02:00
|
|
|
},
|
2017-10-05 12:35:01 +02:00
|
|
|
_ => (None, special_endpoint(&path_segments)),
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 14:45:09 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
fn default_port(url: &Uri, extra_port: Option<u16>) -> u16 {
|
|
|
|
let scheme = url.scheme().unwrap_or("http");
|
|
|
|
url.port().or(extra_port).unwrap_or_else(|| match scheme {
|
|
|
|
"http" => 80,
|
|
|
|
"https" => 443,
|
|
|
|
_ => 80,
|
|
|
|
})
|
|
|
|
}
|
2016-05-12 15:05:59 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::{SpecialEndpoint, EndpointPath, extract_endpoint};
|
2016-05-12 15:05:59 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
#[test]
|
|
|
|
fn should_extract_endpoint() {
|
|
|
|
let dapps_domain = ".web3.site";
|
2016-05-13 18:40:20 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
// With path prefix
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://localhost:8080/status/index.html?q=1".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["index.html".to_owned()],
|
|
|
|
query: Some("q=1".into()),
|
|
|
|
host: "localhost".to_owned(),
|
|
|
|
port: 8080,
|
|
|
|
using_dapps_domains: false,
|
|
|
|
}), SpecialEndpoint::None)
|
|
|
|
);
|
2016-05-12 15:05:59 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
// With path prefix
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://localhost:8080/rpc/".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "rpc".to_owned(),
|
|
|
|
app_params: vec!["".to_owned()],
|
|
|
|
query: None,
|
|
|
|
host: "localhost".to_owned(),
|
|
|
|
port: 8080,
|
|
|
|
using_dapps_domains: false,
|
|
|
|
}), SpecialEndpoint::Rpc)
|
|
|
|
);
|
2016-05-12 17:13:26 +02:00
|
|
|
|
2017-10-05 12:35:01 +02:00
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://my.status.web3.site/parity-utils/inject.js".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".into(), "inject.js".into()],
|
|
|
|
query: None,
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
|
|
|
port: 80,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), SpecialEndpoint::Utils)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://my.status.web3.site/inject.js".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".into(), "inject.js".into()],
|
|
|
|
query: None,
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
|
|
|
port: 80,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), SpecialEndpoint::None)
|
|
|
|
);
|
|
|
|
|
|
|
|
// By Subdomain
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://status.web3.site/test.html".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["test.html".to_owned()],
|
|
|
|
query: None,
|
|
|
|
host: "status.web3.site".to_owned(),
|
|
|
|
port: 80,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), SpecialEndpoint::None)
|
|
|
|
);
|
|
|
|
|
|
|
|
// RPC by subdomain
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://my.status.web3.site/rpc/".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".into(), "".into()],
|
|
|
|
query: None,
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
|
|
|
port: 80,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), SpecialEndpoint::Rpc)
|
|
|
|
);
|
|
|
|
|
|
|
|
// API by subdomain
|
|
|
|
assert_eq!(
|
|
|
|
extract_endpoint(&"http://my.status.web3.site/api/".parse().unwrap(), None, dapps_domain),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".into(), "".into()],
|
|
|
|
query: None,
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
|
|
|
port: 80,
|
|
|
|
using_dapps_domains: true,
|
|
|
|
}), SpecialEndpoint::Api)
|
|
|
|
);
|
|
|
|
}
|
2016-05-12 14:45:09 +02:00
|
|
|
}
|