mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Urlmageddon: Use refcounted urls more often.
This commit is contained in:
parent
f14e7339b5
commit
913c874cb5
161 changed files with 1044 additions and 718 deletions
|
@ -2,12 +2,12 @@
|
|||
* 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 servo_url::ServoUrl;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
use std::net::IpAddr;
|
||||
use url::Url;
|
||||
|
||||
lazy_static! {
|
||||
static ref HOST_TABLE: Option<HashMap<String, IpAddr>> = create_host_table();
|
||||
|
@ -52,14 +52,14 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
|
|||
host_table
|
||||
}
|
||||
|
||||
pub fn replace_hosts(url: &Url) -> Url {
|
||||
pub fn replace_hosts(url: &ServoUrl) -> ServoUrl {
|
||||
HOST_TABLE.as_ref().map_or_else(|| url.clone(), |host_table| {
|
||||
host_replacement(host_table, url)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn host_replacement(host_table: &HashMap<String, IpAddr>,
|
||||
url: &Url) -> Url {
|
||||
url: &ServoUrl) -> ServoUrl {
|
||||
url.domain().and_then(|domain| host_table.get(domain).map(|ip| {
|
||||
let mut new_url = url.clone();
|
||||
new_url.set_ip_host(*ip).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue