mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Move hosts module into net crate. Remove obsolete functions.
This commit is contained in:
parent
e772086b8c
commit
6f590a87bf
11 changed files with 13 additions and 45 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1687,6 +1687,7 @@ dependencies = [
|
|||
"hyper_serde 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"immeta 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1694,6 +1695,7 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"openssl 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parse-hosts 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"profile_traits 0.0.1",
|
||||
"serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1760,7 +1762,6 @@ dependencies = [
|
|||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parse-hosts 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"servo_config 0.0.1",
|
||||
|
|
|
@ -20,6 +20,7 @@ hyper_serde = "0.6"
|
|||
hyper-openssl = "0.2.2"
|
||||
immeta = "0.3.1"
|
||||
ipc-channel = "0.7"
|
||||
lazy_static = "0.2"
|
||||
log = "0.3.5"
|
||||
matches = "0.1"
|
||||
mime = "0.2.1"
|
||||
|
@ -27,6 +28,7 @@ mime_guess = "1.8.0"
|
|||
msg = {path = "../msg"}
|
||||
net_traits = {path = "../net_traits"}
|
||||
openssl = "0.9"
|
||||
parse-hosts = "0.3.0"
|
||||
profile_traits = {path = "../profile_traits"}
|
||||
serde = "0.9"
|
||||
serde_derive = "0.9"
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use hosts::replace_host;
|
||||
use hyper::client::Pool;
|
||||
use hyper::error::{Result as HyperResult, Error as HyperError};
|
||||
use hyper::net::{NetworkConnector, HttpsStream, HttpStream, SslClient};
|
||||
use hyper_openssl::OpensslClient;
|
||||
use net_traits::hosts::replace_host;
|
||||
use openssl::ssl::{SSL_OP_NO_COMPRESSION, SSL_OP_NO_SSLV2, SSL_OP_NO_SSLV3};
|
||||
use openssl::ssl::{SslConnectorBuilder, SslMethod};
|
||||
use std::io;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use parse_hosts::HostsFile;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
@ -62,19 +61,3 @@ pub fn replace_host(host: &str) -> Cow<str> {
|
|||
.and_then(|table| table.get(host))
|
||||
.map_or(host.into(), |replaced_host| replaced_host.to_string().into())
|
||||
}
|
||||
|
||||
pub fn replace_host_in_url(url: ServoUrl) -> ServoUrl {
|
||||
if let Some(table) = HOST_TABLE.lock().unwrap().as_ref() {
|
||||
host_replacement(table, url)
|
||||
} else {
|
||||
url
|
||||
}
|
||||
}
|
||||
|
||||
pub fn host_replacement(host_table: &HashMap<String, IpAddr>, mut url: ServoUrl) -> ServoUrl {
|
||||
let replacement = url.domain().and_then(|domain| host_table.get(domain));
|
||||
if let Some(ip) = replacement {
|
||||
url.set_ip_host(*ip).unwrap();
|
||||
}
|
||||
url
|
||||
}
|
|
@ -16,6 +16,8 @@ extern crate hyper_openssl;
|
|||
extern crate hyper_serde;
|
||||
extern crate immeta;
|
||||
extern crate ipc_channel;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] #[no_link] extern crate matches;
|
||||
#[macro_use]
|
||||
|
@ -24,6 +26,7 @@ extern crate mime_guess;
|
|||
extern crate msg;
|
||||
extern crate net_traits;
|
||||
extern crate openssl;
|
||||
extern crate parse_hosts;
|
||||
extern crate profile_traits;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
|
@ -47,6 +50,7 @@ pub mod cookie;
|
|||
pub mod cookie_storage;
|
||||
mod data_loader;
|
||||
pub mod filemanager_thread;
|
||||
mod hosts;
|
||||
pub mod hsts;
|
||||
mod http_loader;
|
||||
pub mod image_cache;
|
||||
|
@ -65,4 +69,5 @@ pub mod fetch {
|
|||
pub mod test {
|
||||
pub use chrome_loader::resolve_chrome_url;
|
||||
pub use http_loader::HttpState;
|
||||
pub use hosts::{replace_host_table, parse_hostsfile};
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use cookie::Cookie;
|
||||
use fetch::methods::{should_be_blocked_due_to_bad_port, should_be_blocked_due_to_nosniff};
|
||||
use hosts::replace_host;
|
||||
use http_loader::{HttpState, is_redirect_status, set_default_accept};
|
||||
use http_loader::{set_default_accept_language, set_request_cookies};
|
||||
use hyper::buffer::BufReader;
|
||||
|
@ -16,7 +17,6 @@ use hyper::status::StatusCode;
|
|||
use hyper::version::HttpVersion;
|
||||
use net_traits::{CookieSource, MessageData, NetworkError, WebSocketCommunicate, WebSocketConnectData};
|
||||
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
|
||||
use net_traits::hosts::replace_host;
|
||||
use net_traits::request::{Destination, Type};
|
||||
use servo_url::ServoUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
|
|
|
@ -22,7 +22,6 @@ lazy_static = "0.2"
|
|||
log = "0.3.5"
|
||||
msg = {path = "../msg"}
|
||||
num-traits = "0.1.32"
|
||||
parse-hosts = "0.3.0"
|
||||
serde = "0.9"
|
||||
serde_derive = "0.9"
|
||||
servo_config = {path = "../config", features = ["servo"]}
|
||||
|
|
|
@ -22,7 +22,6 @@ extern crate lazy_static;
|
|||
extern crate log;
|
||||
extern crate msg;
|
||||
extern crate num_traits;
|
||||
extern crate parse_hosts;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
@ -51,7 +50,6 @@ use storage_thread::StorageThreadMsg;
|
|||
|
||||
pub mod blob_url_store;
|
||||
pub mod filemanager_thread;
|
||||
pub mod hosts;
|
||||
pub mod image_cache;
|
||||
pub mod net_error_list;
|
||||
pub mod pub_domains;
|
||||
|
|
|
@ -6,7 +6,6 @@ use net::hsts::{HstsEntry, HstsList};
|
|||
use net_traits::IncludeSubdomains;
|
||||
use std::collections::HashMap;
|
||||
use time;
|
||||
use url::Url;
|
||||
|
||||
#[test]
|
||||
fn test_hsts_entry_is_not_expired_when_it_has_no_timestamp() {
|
||||
|
|
|
@ -25,8 +25,8 @@ use msg::constellation_msg::TEST_PIPELINE_ID;
|
|||
use net::cookie::Cookie;
|
||||
use net::cookie_storage::CookieStorage;
|
||||
use net::resource_thread::AuthCacheEntry;
|
||||
use net::test::replace_host_table;
|
||||
use net_traits::{CookieSource, NetworkError};
|
||||
use net_traits::hosts::replace_host_table;
|
||||
use net_traits::request::{Request, RequestInit, RequestMode, CredentialsMode, Destination};
|
||||
use net_traits::response::ResponseBody;
|
||||
use new_fetch_context;
|
||||
|
|
|
@ -4,12 +4,9 @@
|
|||
|
||||
use ipc_channel::ipc;
|
||||
use net::resource_thread::new_core_resource_thread;
|
||||
use net::test::parse_hostsfile;
|
||||
use net_traits::CoreResourceMsg;
|
||||
use net_traits::hosts::{host_replacement, parse_hostsfile};
|
||||
use profile_traits::time::ProfilerChan;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
|
||||
fn ip(s: &str) -> IpAddr {
|
||||
|
@ -143,19 +140,3 @@ fn test_parse_hostsfile_with_end_of_line_whitespace()
|
|||
assert_eq!(ip("2001:db8:0:0:0:ff00:42:8329"), *hosts_table.get("moz.foo.com").unwrap());
|
||||
assert_eq!(ip("127.0.0.2"), *hosts_table.get("servo.test.server").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_hosts() {
|
||||
let mut host_table = HashMap::new();
|
||||
host_table.insert("foo.bar.com".to_owned(), ip("127.0.0.1"));
|
||||
host_table.insert("servo.test.server".to_owned(), ip("127.0.0.2"));
|
||||
|
||||
let url = ServoUrl::parse("http://foo.bar.com:8000/foo").unwrap();
|
||||
assert_eq!(host_replacement(&host_table, url).host_str().unwrap(), "127.0.0.1");
|
||||
|
||||
let url = ServoUrl::parse("http://servo.test.server").unwrap();
|
||||
assert_eq!(host_replacement(&host_table, url).host_str().unwrap(), "127.0.0.2");
|
||||
|
||||
let url = ServoUrl::parse("http://a.foo.bar.com").unwrap();
|
||||
assert_eq!(host_replacement(&host_table, url).host_str().unwrap(), "a.foo.bar.com");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue