Use NetworkConnector directly to account for replaced hosts

This let us remove a hack where we had to replace the host in the request URL.
This commit is contained in:
Anthony Ramine 2017-03-25 15:14:20 +01:00
parent 54d37d920c
commit 92c4a43946
2 changed files with 22 additions and 8 deletions

View file

@ -4,6 +4,7 @@
use parse_hosts::HostsFile;
use servo_url::ServoUrl;
use std::borrow::Cow;
use std::collections::HashMap;
use std::env;
use std::fs::File;
@ -56,6 +57,12 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
host_table
}
pub fn replace_host(host: &str) -> Cow<str> {
HOST_TABLE.lock().unwrap().as_ref()
.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)