mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
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:
parent
54d37d920c
commit
92c4a43946
2 changed files with 22 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue