aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-23 08:55:54 -0800
committerGitHub <noreply@github.com>2016-11-23 08:55:54 -0800
commitbc1e18c29e4f53ca8ed38cf2bc4e7cd912d70f93 (patch)
treeaa8f7369529ec2740338c3e418bf158b9c20bddc /components
parentc4b7cc863eb9c0387577be33db4e2c0a6fd92a60 (diff)
parent04ffeea3c53362e8dd0f5583ffb5b00e0492bd8e (diff)
downloadservo-bc1e18c29e4f53ca8ed38cf2bc4e7cd912d70f93.tar.gz
servo-bc1e18c29e4f53ca8ed38cf2bc4e7cd912d70f93.zip
Auto merge of #14345 - servo:cookies-host, r=jdm
Rewrite test_redirect_from_x_to_y_provides_y_cookies_from_y. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14345) <!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r--components/net_traits/hosts.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/components/net_traits/hosts.rs b/components/net_traits/hosts.rs
index 0a42be55572..c3c48ce9938 100644
--- a/components/net_traits/hosts.rs
+++ b/components/net_traits/hosts.rs
@@ -8,9 +8,10 @@ use std::env;
use std::fs::File;
use std::io::{BufReader, Read};
use std::net::IpAddr;
+use std::sync::Mutex;
lazy_static! {
- static ref HOST_TABLE: Option<HashMap<String, IpAddr>> = create_host_table();
+ static ref HOST_TABLE: Mutex<Option<HashMap<String, IpAddr>>> = Mutex::new(create_host_table());
}
fn create_host_table() -> Option<HashMap<String, IpAddr>> {
@@ -34,13 +35,17 @@ fn create_host_table() -> Option<HashMap<String, IpAddr>> {
return Some(parse_hostsfile(&lines));
}
+pub fn replace_host_table(table: HashMap<String, IpAddr>) {
+ *HOST_TABLE.lock().unwrap() = Some(table);
+}
+
pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
let mut host_table = HashMap::new();
for line in hostsfile_content.split('\n') {
- let ip_host: Vec<&str> = line.trim().split(|c: char| c == ' ' || c == '\t').collect();
- if ip_host.len() > 1 {
- if let Ok(address) = ip_host[0].parse::<IpAddr>() {
- for token in ip_host.iter().skip(1) {
+ let mut ip_host = line.trim().split(|c: char| c == ' ' || c == '\t');
+ if let Some(ip) = ip_host.next() {
+ if let Ok(address) = ip.parse::<IpAddr>() {
+ for token in ip_host {
if token.as_bytes()[0] == b'#' {
break;
}
@@ -53,7 +58,7 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
}
pub fn replace_hosts(url: &ServoUrl) -> ServoUrl {
- HOST_TABLE.as_ref().map_or_else(|| url.clone(), |host_table| {
+ HOST_TABLE.lock().unwrap().as_ref().map_or_else(|| url.clone(), |host_table| {
host_replacement(host_table, url)
})
}