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
|
2016-04-08 15:25:20 +02:00
|
|
|
//! Processes request handling authorization and dispatching it to proper application.
|
|
|
|
|
2016-04-08 16:11:58 +02:00
|
|
|
pub mod auth;
|
2016-07-20 12:34:17 +02:00
|
|
|
mod host_validation;
|
2016-04-07 12:10:26 +02:00
|
|
|
|
2016-11-09 19:41:47 +01:00
|
|
|
use address;
|
2016-12-27 11:15:02 +01:00
|
|
|
use std::cmp;
|
2016-04-07 18:22:53 +02:00
|
|
|
use std::sync::Arc;
|
2016-05-13 18:40:20 +02:00
|
|
|
use std::collections::HashMap;
|
2016-07-07 09:42:49 +02:00
|
|
|
use url::{Url, Host};
|
2016-12-27 11:15:02 +01:00
|
|
|
use hyper::{self, server, header, Next, Encoder, Decoder, Control, StatusCode};
|
2016-04-14 20:38:48 +02:00
|
|
|
use hyper::net::HttpStream;
|
2016-10-22 15:21:41 +02:00
|
|
|
use apps::{self, DAPPS_DOMAIN};
|
2016-12-22 18:26:39 +01:00
|
|
|
use apps::fetcher::Fetcher;
|
2016-05-12 17:13:26 +02:00
|
|
|
use endpoint::{Endpoint, Endpoints, EndpointPath};
|
2016-12-27 11:15:02 +01:00
|
|
|
use handlers::{self, Redirection, ContentHandler};
|
2016-04-08 16:11:58 +02:00
|
|
|
use self::auth::{Authorization, Authorized};
|
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,
|
2016-05-16 20:22:19 +02:00
|
|
|
None,
|
2016-05-12 17:13:26 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 20:38:48 +02:00
|
|
|
pub struct Router<A: Authorization + 'static> {
|
2016-08-18 12:19:09 +02:00
|
|
|
control: Option<Control>,
|
2016-11-09 19:41:47 +01:00
|
|
|
signer_address: Option<(String, u16)>,
|
2016-04-14 20:38:48 +02:00
|
|
|
endpoints: Arc<Endpoints>,
|
2016-12-22 18:26:39 +01:00
|
|
|
fetch: Arc<Fetcher>,
|
2016-05-13 18:40:20 +02:00
|
|
|
special: Arc<HashMap<SpecialEndpoint, Box<Endpoint>>>,
|
2016-04-14 20:38:48 +02:00
|
|
|
authorization: Arc<A>,
|
2016-08-25 08:57:13 +02:00
|
|
|
allowed_hosts: Option<Vec<String>>,
|
2016-06-27 10:39:37 +02:00
|
|
|
handler: Box<server::Handler<HttpStream> + Send>,
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 20:38:48 +02:00
|
|
|
impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {
|
|
|
|
|
2016-06-27 10:39:37 +02:00
|
|
|
fn on_request(&mut self, req: server::Request<HttpStream>) -> Next {
|
2016-09-01 10:16:04 +02:00
|
|
|
// Choose proper handler depending on path / domain
|
2016-12-27 11:15:02 +01:00
|
|
|
let url = handlers::extract_url(&req);
|
2016-09-01 10:16:04 +02:00
|
|
|
let endpoint = extract_endpoint(&url);
|
2016-12-27 11:15:02 +01:00
|
|
|
let referer = extract_referer_endpoint(&req);
|
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;
|
2016-09-01 10:16:04 +02:00
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Routing request to {:?}. Details: {:?}", url, req);
|
|
|
|
|
2016-07-20 12:34:17 +02:00
|
|
|
// Validate Host header
|
2016-08-25 08:57:13 +02:00
|
|
|
if let Some(ref hosts) = self.allowed_hosts {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Validating host headers against: {:?}", hosts);
|
2016-09-01 10:16:04 +02:00
|
|
|
let is_valid = is_utils || host_validation::is_valid(&req, hosts, self.endpoints.keys().cloned().collect());
|
|
|
|
if !is_valid {
|
2016-10-22 15:21:41 +02:00
|
|
|
debug!(target: "dapps", "Rejecting invalid host header.");
|
2016-08-25 08:57:13 +02:00
|
|
|
self.handler = host_validation::host_invalid_response();
|
|
|
|
return self.handler.on_request(req);
|
|
|
|
}
|
2016-07-20 12:34:17 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Checking authorization.");
|
2016-05-12 14:45:09 +02:00
|
|
|
// Check authorization
|
2016-04-14 20:38:48 +02:00
|
|
|
let auth = self.authorization.is_authorized(&req);
|
2016-07-20 12:34:17 +02:00
|
|
|
if let Authorized::No(handler) = auth {
|
2016-10-22 15:21:41 +02:00
|
|
|
debug!(target: "dapps", "Authorization denied.");
|
2016-07-20 12:34:17 +02:00
|
|
|
self.handler = handler;
|
|
|
|
return self.handler.on_request(req);
|
|
|
|
}
|
2016-05-12 14:45:09 +02:00
|
|
|
|
2016-12-27 11:15:02 +01:00
|
|
|
|
2016-09-01 12:00:00 +02:00
|
|
|
let control = self.control.take().expect("on_request is called only once; control is always defined at start; qed");
|
2016-10-22 15:21:41 +02:00
|
|
|
debug!(target: "dapps", "Handling endpoint request: {:?}", endpoint);
|
2016-12-27 11:15:02 +01:00
|
|
|
self.handler = match (endpoint.0, endpoint.1, referer) {
|
|
|
|
// Handle invalid web requests that we can recover from
|
|
|
|
(ref path, SpecialEndpoint::None, Some((ref referer, ref referer_url)))
|
2017-01-16 10:49:27 +01:00
|
|
|
if referer.app_id == apps::WEB_PATH
|
2016-12-27 11:15:02 +01:00
|
|
|
&& self.endpoints.contains_key(apps::WEB_PATH)
|
|
|
|
&& !is_web_endpoint(path)
|
|
|
|
=>
|
|
|
|
{
|
|
|
|
trace!(target: "dapps", "Redirecting to correct web request: {:?}", referer_url);
|
2017-02-04 09:52:14 +01:00
|
|
|
let len = cmp::min(referer_url.path.len(), 2); // /web/<encoded>/
|
2016-12-27 11:15:02 +01:00
|
|
|
let base = referer_url.path[..len].join("/");
|
|
|
|
let requested = url.map(|u| u.path.join("/")).unwrap_or_default();
|
|
|
|
Redirection::boxed(&format!("/{}/{}", base, requested))
|
|
|
|
},
|
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.");
|
2016-10-20 23:41:15 +02:00
|
|
|
self.special.get(endpoint)
|
|
|
|
.expect("special known to contain key; qed")
|
|
|
|
.to_async_handler(path.clone().unwrap_or_default(), control)
|
2016-07-20 12:34:17 +02:00
|
|
|
},
|
|
|
|
// Then delegate to dapp
|
2016-12-27 11:15:02 +01:00
|
|
|
(Some(ref path), _, _) if self.endpoints.contains_key(&path.app_id) => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to local/builtin dapp.");
|
2016-10-20 23:41:15 +02:00
|
|
|
self.endpoints.get(&path.app_id)
|
2016-12-27 11:15:02 +01:00
|
|
|
.expect("endpoints known to contain key; qed")
|
2016-10-20 23:41:15 +02:00
|
|
|
.to_async_handler(path.clone(), control)
|
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.");
|
2016-09-01 12:00:00 +02:00
|
|
|
self.fetch.to_async_handler(path.clone(), control)
|
2016-08-18 12:19:09 +02:00
|
|
|
},
|
2016-11-02 11:29:18 +01:00
|
|
|
// NOTE [todr] /home is redirected to home page since some users may have the redirection cached
|
|
|
|
// (in the past we used 301 instead of 302)
|
|
|
|
// It should be safe to remove it in (near) future.
|
|
|
|
//
|
2016-09-22 18:05:36 +02:00
|
|
|
// 404 for non-existent content
|
2016-12-27 11:15:02 +01:00
|
|
|
(Some(ref path), _, _) if is_get_request && path.app_id != "home" => {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Resolving to 404.");
|
2016-09-01 11:16:19 +02:00
|
|
|
Box::new(ContentHandler::error(
|
|
|
|
StatusCode::NotFound,
|
|
|
|
"404 Not Found",
|
2016-09-01 12:01:44 +02:00
|
|
|
"Requested content was not found.",
|
2016-10-22 15:21:41 +02:00
|
|
|
None,
|
2016-11-09 19:41:47 +01:00
|
|
|
self.signer_address.clone(),
|
2016-09-01 11:16:19 +02:00
|
|
|
))
|
2016-07-20 12:34:17 +02:00
|
|
|
},
|
2016-10-22 15:21:41 +02:00
|
|
|
// Redirect any other GET request to signer.
|
2016-12-27 11:15:02 +01:00
|
|
|
_ if is_get_request => {
|
2017-02-08 00:11:42 +01:00
|
|
|
if let Some(ref signer_address) = self.signer_address {
|
2016-10-22 15:21:41 +02:00
|
|
|
trace!(target: "dapps", "Redirecting to signer interface.");
|
2016-11-09 19:41:47 +01:00
|
|
|
Redirection::boxed(&format!("http://{}", address(signer_address)))
|
2016-10-22 15:21:41 +02:00
|
|
|
} else {
|
|
|
|
trace!(target: "dapps", "Signer disabled, returning 404.");
|
|
|
|
Box::new(ContentHandler::error(
|
|
|
|
StatusCode::NotFound,
|
|
|
|
"404 Not Found",
|
|
|
|
"Your homepage is not available when Trusted Signer is disabled.",
|
2016-11-11 08:52:52 +01:00
|
|
|
Some("You can still access dapps by writing a correct address, though. Re-enable Signer to get your homepage back."),
|
2016-11-09 19:41:47 +01:00
|
|
|
self.signer_address.clone(),
|
2016-10-22 15:21:41 +02:00
|
|
|
))
|
|
|
|
}
|
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.");
|
2016-10-20 23:41:15 +02:00
|
|
|
self.special.get(&SpecialEndpoint::Rpc)
|
|
|
|
.expect("RPC endpoint always stored; qed")
|
|
|
|
.to_async_handler(EndpointPath::default(), control)
|
2016-04-08 15:25:20 +02:00
|
|
|
}
|
2016-04-14 20:38:48 +02:00
|
|
|
};
|
2016-05-12 14:45:09 +02:00
|
|
|
|
2016-04-14 20:38:48 +02:00
|
|
|
// Delegate on_request to proper handler
|
2016-05-12 14:45:09 +02:00
|
|
|
self.handler.on_request(req)
|
2016-04-14 20:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This event occurs each time the `Request` is ready to be read from.
|
|
|
|
fn on_request_readable(&mut self, decoder: &mut Decoder<HttpStream>) -> Next {
|
|
|
|
self.handler.on_request_readable(decoder)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This event occurs after the first time this handled signals `Next::write()`.
|
|
|
|
fn on_response(&mut self, response: &mut server::Response) -> Next {
|
|
|
|
self.handler.on_response(response)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This event occurs each time the `Response` is ready to be written to.
|
|
|
|
fn on_response_writable(&mut self, encoder: &mut Encoder<HttpStream>) -> Next {
|
|
|
|
self.handler.on_response_writable(encoder)
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 16:11:58 +02:00
|
|
|
impl<A: Authorization> Router<A> {
|
|
|
|
pub fn new(
|
2016-08-18 12:19:09 +02:00
|
|
|
control: Control,
|
2016-11-09 19:41:47 +01:00
|
|
|
signer_address: Option<(String, u16)>,
|
2016-12-22 18:26:39 +01:00
|
|
|
content_fetcher: Arc<Fetcher>,
|
2016-04-14 20:38:48 +02:00
|
|
|
endpoints: Arc<Endpoints>,
|
2016-05-13 18:40:20 +02:00
|
|
|
special: Arc<HashMap<SpecialEndpoint, Box<Endpoint>>>,
|
2016-07-20 12:34:17 +02:00
|
|
|
authorization: Arc<A>,
|
2016-08-25 08:57:13 +02:00
|
|
|
allowed_hosts: Option<Vec<String>>,
|
2016-07-20 12:34:17 +02:00
|
|
|
) -> Self {
|
2016-04-14 20:38:48 +02:00
|
|
|
|
2016-10-20 23:41:15 +02:00
|
|
|
let handler = special.get(&SpecialEndpoint::Utils)
|
|
|
|
.expect("Utils endpoint always stored; qed")
|
|
|
|
.to_handler(EndpointPath::default());
|
2016-04-07 12:10:26 +02:00
|
|
|
Router {
|
2016-08-18 12:19:09 +02:00
|
|
|
control: Some(control),
|
2016-11-09 19:41:47 +01:00
|
|
|
signer_address: signer_address,
|
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,
|
2016-04-14 20:38:48 +02:00
|
|
|
authorization: authorization,
|
2016-08-25 08:57:13 +02:00
|
|
|
allowed_hosts: allowed_hosts,
|
2016-04-14 20:38:48 +02:00
|
|
|
handler: handler,
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn extract_referer_endpoint(req: &server::Request<HttpStream>) -> Option<(EndpointPath, Url)> {
|
|
|
|
let referer = req.headers().get::<header::Referer>();
|
|
|
|
|
|
|
|
let url = referer.and_then(|referer| Url::parse(&referer.0).ok());
|
|
|
|
url.and_then(|url| {
|
|
|
|
let option = Some(url);
|
2017-01-16 10:49:27 +01:00
|
|
|
extract_url_referer_endpoint(&option).or_else(|| {
|
|
|
|
extract_endpoint(&option).0.map(|endpoint| (endpoint, option.expect("Just wrapped; qed")))
|
|
|
|
})
|
2016-12-27 11:15:02 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:27 +01:00
|
|
|
fn extract_url_referer_endpoint(url: &Option<Url>) -> Option<(EndpointPath, Url)> {
|
|
|
|
let query = url.as_ref().and_then(|url| url.query.as_ref());
|
|
|
|
match (url, query) {
|
|
|
|
(&Some(ref url), Some(ref query)) if query.starts_with(apps::URL_REFERER) => {
|
|
|
|
let referer_url = format!("http://{}:{}/{}", url.host, url.port, &query[apps::URL_REFERER.len()..]);
|
|
|
|
debug!(target: "dapps", "Recovering referer from query parameter: {}", referer_url);
|
|
|
|
|
|
|
|
let referer_url = Url::parse(&referer_url).ok();
|
|
|
|
extract_endpoint(&referer_url).0.map(|endpoint| {
|
|
|
|
(endpoint, referer_url.expect("Endpoint returned only when url `is_some`").clone())
|
|
|
|
})
|
|
|
|
},
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 17:13:26 +02:00
|
|
|
fn extract_endpoint(url: &Option<Url>) -> (Option<EndpointPath>, SpecialEndpoint) {
|
|
|
|
fn special_endpoint(url: &Url) -> SpecialEndpoint {
|
|
|
|
if url.path.len() <= 1 {
|
|
|
|
return SpecialEndpoint::None;
|
|
|
|
}
|
2016-05-13 18:40:20 +02:00
|
|
|
|
2016-05-12 17:13:26 +02:00
|
|
|
match url.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,
|
2016-05-12 17:13:26 +02:00
|
|
|
_ => SpecialEndpoint::None,
|
|
|
|
}
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 15:05:59 +02:00
|
|
|
match *url {
|
|
|
|
Some(ref url) => match url.host {
|
2016-05-16 16:08:52 +02:00
|
|
|
Host::Domain(ref domain) if domain.ends_with(DAPPS_DOMAIN) => {
|
2017-02-04 09:52:14 +01:00
|
|
|
let id = &domain[0..(domain.len() - DAPPS_DOMAIN.len())];
|
|
|
|
let (id, params) = if let Some(split) = id.rfind('.') {
|
|
|
|
let (params, id) = id.split_at(split);
|
|
|
|
(id[1..].to_owned(), [params.to_owned()].into_iter().chain(&url.path).cloned().collect())
|
|
|
|
} else {
|
|
|
|
(id.to_owned(), url.path.clone())
|
|
|
|
};
|
2016-05-12 15:05:59 +02:00
|
|
|
|
2016-05-12 17:13:26 +02:00
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: id,
|
2017-02-04 09:52:14 +01:00
|
|
|
app_params: params,
|
2016-05-12 17:13:26 +02:00
|
|
|
host: domain.clone(),
|
|
|
|
port: url.port,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: true,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), special_endpoint(url))
|
2016-05-12 15:05:59 +02:00
|
|
|
},
|
|
|
|
_ if url.path.len() > 1 => {
|
2017-02-04 09:52:14 +01:00
|
|
|
let id = url.path[0].to_owned();
|
2016-05-12 17:13:26 +02:00
|
|
|
(Some(EndpointPath {
|
2017-02-04 09:52:14 +01:00
|
|
|
app_id: id,
|
|
|
|
app_params: url.path[1..].to_vec(),
|
2016-05-12 17:13:26 +02:00
|
|
|
host: format!("{}", url.host),
|
|
|
|
port: url.port,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: false,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), special_endpoint(url))
|
2016-04-07 15:14:39 +02:00
|
|
|
},
|
2016-05-12 17:13:26 +02:00
|
|
|
_ => (None, special_endpoint(url)),
|
2016-05-12 15:05:59 +02:00
|
|
|
},
|
2016-05-12 17:13:26 +02:00
|
|
|
_ => (None, SpecialEndpoint::None)
|
2016-04-07 12:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 14:45:09 +02:00
|
|
|
|
2016-05-12 15:05:59 +02:00
|
|
|
#[test]
|
2016-05-12 17:13:26 +02:00
|
|
|
fn should_extract_endpoint() {
|
|
|
|
assert_eq!(extract_endpoint(&None), (None, SpecialEndpoint::None));
|
2016-05-12 15:05:59 +02:00
|
|
|
|
|
|
|
// With path prefix
|
|
|
|
assert_eq!(
|
2016-05-12 17:13:26 +02:00
|
|
|
extract_endpoint(&Url::parse("http://localhost:8080/status/index.html").ok()),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "status".to_owned(),
|
2017-02-04 09:52:14 +01:00
|
|
|
app_params: vec!["index.html".to_owned()],
|
2016-05-12 17:13:26 +02:00
|
|
|
host: "localhost".to_owned(),
|
|
|
|
port: 8080,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: false,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), SpecialEndpoint::None)
|
|
|
|
);
|
2016-05-12 15:05:59 +02:00
|
|
|
|
|
|
|
// With path prefix
|
|
|
|
assert_eq!(
|
2016-05-12 17:13:26 +02:00
|
|
|
extract_endpoint(&Url::parse("http://localhost:8080/rpc/").ok()),
|
|
|
|
(Some(EndpointPath {
|
|
|
|
app_id: "rpc".to_owned(),
|
2017-02-04 09:52:14 +01:00
|
|
|
app_params: vec!["".to_owned()],
|
2016-05-12 17:13:26 +02:00
|
|
|
host: "localhost".to_owned(),
|
|
|
|
port: 8080,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: false,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), SpecialEndpoint::Rpc)
|
|
|
|
);
|
2016-05-12 15:05:59 +02:00
|
|
|
|
2016-05-13 18:40:20 +02:00
|
|
|
assert_eq!(
|
2017-02-04 09:52:14 +01:00
|
|
|
extract_endpoint(&Url::parse("http://my.status.web3.site/parity-utils/inject.js").ok()),
|
2016-05-13 18:40:20 +02:00
|
|
|
(Some(EndpointPath {
|
2017-02-04 09:52:14 +01:00
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".to_owned(), "parity-utils".into(), "inject.js".into()],
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
2016-05-13 18:40:20 +02:00
|
|
|
port: 80,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: true,
|
2016-05-13 18:40:20 +02:00
|
|
|
}), SpecialEndpoint::Utils)
|
|
|
|
);
|
|
|
|
|
2016-05-12 15:05:59 +02:00
|
|
|
// By Subdomain
|
|
|
|
assert_eq!(
|
2017-02-04 09:52:14 +01:00
|
|
|
extract_endpoint(&Url::parse("http://status.web3.site/test.html").ok()),
|
2016-05-12 17:13:26 +02:00
|
|
|
(Some(EndpointPath {
|
2017-02-04 09:52:14 +01:00
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["test.html".to_owned()],
|
|
|
|
host: "status.web3.site".to_owned(),
|
2016-05-12 17:13:26 +02:00
|
|
|
port: 80,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: true,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), SpecialEndpoint::None)
|
|
|
|
);
|
2016-05-12 15:05:59 +02:00
|
|
|
|
|
|
|
// RPC by subdomain
|
|
|
|
assert_eq!(
|
2017-02-04 09:52:14 +01:00
|
|
|
extract_endpoint(&Url::parse("http://my.status.web3.site/rpc/").ok()),
|
2016-05-12 17:13:26 +02:00
|
|
|
(Some(EndpointPath {
|
2017-02-04 09:52:14 +01:00
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".to_owned(), "rpc".into(), "".into()],
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
2016-05-12 17:13:26 +02:00
|
|
|
port: 80,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: true,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), SpecialEndpoint::Rpc)
|
|
|
|
);
|
|
|
|
|
|
|
|
// API by subdomain
|
|
|
|
assert_eq!(
|
2017-02-04 09:52:14 +01:00
|
|
|
extract_endpoint(&Url::parse("http://my.status.web3.site/api/").ok()),
|
2016-05-12 17:13:26 +02:00
|
|
|
(Some(EndpointPath {
|
2017-02-04 09:52:14 +01:00
|
|
|
app_id: "status".to_owned(),
|
|
|
|
app_params: vec!["my".to_owned(), "api".into(), "".into()],
|
|
|
|
host: "my.status.web3.site".to_owned(),
|
2016-05-12 17:13:26 +02:00
|
|
|
port: 80,
|
2016-08-23 19:28:21 +02:00
|
|
|
using_dapps_domains: true,
|
2016-05-12 17:13:26 +02:00
|
|
|
}), SpecialEndpoint::Api)
|
|
|
|
);
|
2016-05-12 14:45:09 +02:00
|
|
|
}
|