Upgrade to url v2.0 (#583)

This commit is contained in:
Nikhil Benesch
2019-09-04 21:27:20 -04:00
committed by Sean McArthur
parent cf8944a0f0
commit f60456c8e3
4 changed files with 42 additions and 39 deletions

View File

@@ -27,15 +27,16 @@ flate2 = { version = "^1.0.7", default-features = false, features = ["rust_backe
log = "0.4" log = "0.4"
mime = "0.3.7" mime = "0.3.7"
mime_guess = "2.0" mime_guess = "2.0"
percent-encoding = "2.1"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"
serde_urlencoded = "0.5" serde_urlencoded = "0.6.1"
tokio = { version = "0.1.7", default-features = false, features = ["rt-full", "tcp"] } tokio = { version = "0.1.7", default-features = false, features = ["rt-full", "tcp"] }
tokio-executor = "0.1.4" # a minimum version so trust-dns-resolver compiles tokio-executor = "0.1.4" # a minimum version so trust-dns-resolver compiles
tokio-io = "0.1" tokio-io = "0.1"
tokio-threadpool = "0.1.8" # a minimum version so tokio compiles tokio-threadpool = "0.1.8" # a minimum version so tokio compiles
tokio-timer = "0.2.6" # a minimum version so trust-dns-resolver compiles tokio-timer = "0.2.6" # a minimum version so trust-dns-resolver compiles
url = "1.2" url = "2.1"
uuid = { version = "0.7", features = ["v4"] } uuid = { version = "0.7", features = ["v4"] }
# Optional deps... # Optional deps...
@@ -49,7 +50,7 @@ socks = { version = "0.3.2", optional = true }
tokio-rustls = { version = "0.10", optional = true } tokio-rustls = { version = "0.10", optional = true }
trust-dns-resolver = { version = "0.11", optional = true } trust-dns-resolver = { version = "0.11", optional = true }
webpki-roots = { version = "0.17", optional = true } webpki-roots = { version = "0.17", optional = true }
cookie_store = "0.7.0" cookie_store = "0.9.0"
cookie = "0.12.0" cookie = "0.12.0"
time = "0.1.42" time = "0.1.42"

View File

@@ -4,7 +4,7 @@ use std::fmt;
use http::HeaderMap; use http::HeaderMap;
use mime_guess::Mime; use mime_guess::Mime;
use url::percent_encoding::{self, EncodeSet, PATH_SEGMENT_ENCODE_SET}; use percent_encoding::{self, AsciiSet, NON_ALPHANUMERIC};
use uuid::Uuid; use uuid::Uuid;
use futures::Stream; use futures::Stream;
@@ -386,33 +386,33 @@ impl PartMetadata {
} }
} }
#[derive(Debug, Clone)] /// https://url.spec.whatwg.org/#fragment-percent-encode-set
pub(crate) struct AttrCharEncodeSet; const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
.add(b' ')
.add(b'"')
.add(b'<')
.add(b'>')
.add(b'`');
impl EncodeSet for AttrCharEncodeSet { /// https://url.spec.whatwg.org/#path-percent-encode-set
fn contains(&self, ch: u8) -> bool { const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}');
match ch as char {
'!' => false, const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET.add(b'/').add(b'%');
'#' => false,
'$' => false, /// https://tools.ietf.org/html/rfc8187#section-3.2.1
'&' => false, const ATTR_CHAR_ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
'+' => false, .remove(b'!')
'-' => false, .remove(b'#')
'.' => false, .remove(b'$')
'^' => false, .remove(b'&')
'_' => false, .remove(b'+')
'`' => false, .remove(b'-')
'|' => false, .remove(b'.')
'~' => false, .remove(b'^')
_ => { .remove(b'_')
let is_alpha_numeric = ch >= 0x41 && ch <= 0x5a .remove(b'`')
|| ch >= 0x61 && ch <= 0x7a .remove(b'|')
|| ch >= 0x30 && ch <= 0x39; .remove(b'~');
!is_alpha_numeric
}
}
}
}
pub(crate) enum PercentEncoding { pub(crate) enum PercentEncoding {
PathSegment, PathSegment,
@@ -463,7 +463,7 @@ impl PercentEncoding {
percent_encoding::utf8_percent_encode(value, PATH_SEGMENT_ENCODE_SET).to_string() percent_encoding::utf8_percent_encode(value, PATH_SEGMENT_ENCODE_SET).to_string()
} }
PercentEncoding::AttrChar => { PercentEncoding::AttrChar => {
percent_encoding::utf8_percent_encode(value, AttrCharEncodeSet).to_string() percent_encoding::utf8_percent_encode(value, ATTR_CHAR_ENCODE_SET).to_string()
} }
PercentEncoding::NoOp => value.to_string(), PercentEncoding::NoOp => value.to_string(),
}; };

View File

@@ -4,7 +4,7 @@ use std::io::{self, Cursor, Read};
use bytes::Bytes; use bytes::Bytes;
use futures::{try_ready, Future}; use futures::{try_ready, Future};
use hyper::{self}; use hyper;
use crate::async_impl; use crate::async_impl;

View File

@@ -1,16 +1,16 @@
use std::fmt; use std::fmt;
#[cfg(feature = "socks")] #[cfg(feature = "socks")]
use std::net::{SocketAddr, ToSocketAddrs}; use std::net::SocketAddr;
use std::sync::Arc; use std::sync::Arc;
use crate::{IntoUrl, Url}; use crate::{IntoUrl, Url};
use http::{header::HeaderValue, Uri}; use http::{header::HeaderValue, Uri};
use hyper::client::connect::Destination; use hyper::client::connect::Destination;
use percent_encoding::percent_decode;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::error::Error; use std::error::Error;
use url::percent_encoding::percent_decode;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use winreg::enums::HKEY_CURRENT_USER; use winreg::enums::HKEY_CURRENT_USER;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@@ -326,12 +326,14 @@ impl ProxyScheme {
// Resolve URL to a host and port // Resolve URL to a host and port
#[cfg(feature = "socks")] #[cfg(feature = "socks")]
let to_addr = || { let to_addr = || {
let host_and_port = try_!(url.with_default_port(|url| match url.scheme() { let addrs = try_!(url.socket_addrs(|| match url.scheme() {
"socks5" | "socks5h" => Ok(1080), "socks5" | "socks5h" => Some(1080),
_ => Err(()), _ => None,
})); }));
let mut addr = try_!(host_and_port.to_socket_addrs()); addrs
addr.next().ok_or_else(crate::error::unknown_proxy_scheme) .into_iter()
.next()
.ok_or_else(crate::error::unknown_proxy_scheme)
}; };
let mut scheme = match url.scheme() { let mut scheme = match url.scheme() {