mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Replace parse-hosts crate with 10 lines of code.
This removes 3927 lines of Rust code in 6 crates from the dependency graph: parse-hosts, multistr, bow, extra-default, len-trait, and push-trait. One of these crates doesn’t build in today’s Nightly: https://github.com/rust-lang/rust/issues/46328
This commit is contained in:
parent
66d0a41127
commit
eb3652b3c6
4 changed files with 12 additions and 66 deletions
|
@ -28,7 +28,6 @@ mime_guess = "1.8.0"
|
|||
msg = {path = "../msg"}
|
||||
net_traits = {path = "../net_traits"}
|
||||
openssl = "0.9"
|
||||
parse-hosts = "0.5.0"
|
||||
profile_traits = {path = "../profile_traits"}
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
|
|
@ -2,13 +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 parse_hosts::HostsFile;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -32,10 +31,17 @@ pub fn replace_host_table(table: HashMap<String, IpAddr>) {
|
|||
}
|
||||
|
||||
pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
|
||||
HostsFile::read_buffered(hostsfile_content.as_bytes())
|
||||
.pairs()
|
||||
.filter_map(Result::ok)
|
||||
.collect()
|
||||
hostsfile_content.lines().filter_map(|line| {
|
||||
let mut iter = line.split('#').next().unwrap().split_whitespace();
|
||||
Some((iter.next()?.parse().ok()?, iter))
|
||||
}).flat_map(|(ip, hosts)| {
|
||||
hosts.filter(|host| {
|
||||
let invalid = ['\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']'];
|
||||
host.parse::<Ipv4Addr>().is_err() && !host.contains(&invalid[..])
|
||||
}).map(move |host| {
|
||||
(host.to_owned(), ip)
|
||||
})
|
||||
}).collect()
|
||||
}
|
||||
|
||||
pub fn replace_host(host: &str) -> Cow<str> {
|
||||
|
|
|
@ -24,7 +24,6 @@ extern crate mime_guess;
|
|||
extern crate msg;
|
||||
extern crate net_traits;
|
||||
extern crate openssl;
|
||||
extern crate parse_hosts;
|
||||
extern crate profile_traits;
|
||||
#[macro_use] extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue