Upgrade to url v2.0 (#583)
This commit is contained in:
committed by
Sean McArthur
parent
cf8944a0f0
commit
f60456c8e3
@@ -4,7 +4,7 @@ use std::fmt;
|
||||
|
||||
use http::HeaderMap;
|
||||
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 futures::Stream;
|
||||
@@ -386,33 +386,33 @@ impl PartMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct AttrCharEncodeSet;
|
||||
/// https://url.spec.whatwg.org/#fragment-percent-encode-set
|
||||
const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
|
||||
.add(b' ')
|
||||
.add(b'"')
|
||||
.add(b'<')
|
||||
.add(b'>')
|
||||
.add(b'`');
|
||||
|
||||
impl EncodeSet for AttrCharEncodeSet {
|
||||
fn contains(&self, ch: u8) -> bool {
|
||||
match ch as char {
|
||||
'!' => false,
|
||||
'#' => false,
|
||||
'$' => false,
|
||||
'&' => false,
|
||||
'+' => false,
|
||||
'-' => false,
|
||||
'.' => false,
|
||||
'^' => false,
|
||||
'_' => false,
|
||||
'`' => false,
|
||||
'|' => false,
|
||||
'~' => false,
|
||||
_ => {
|
||||
let is_alpha_numeric = ch >= 0x41 && ch <= 0x5a
|
||||
|| ch >= 0x61 && ch <= 0x7a
|
||||
|| ch >= 0x30 && ch <= 0x39;
|
||||
!is_alpha_numeric
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// https://url.spec.whatwg.org/#path-percent-encode-set
|
||||
const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}');
|
||||
|
||||
const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET.add(b'/').add(b'%');
|
||||
|
||||
/// https://tools.ietf.org/html/rfc8187#section-3.2.1
|
||||
const ATTR_CHAR_ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
|
||||
.remove(b'!')
|
||||
.remove(b'#')
|
||||
.remove(b'$')
|
||||
.remove(b'&')
|
||||
.remove(b'+')
|
||||
.remove(b'-')
|
||||
.remove(b'.')
|
||||
.remove(b'^')
|
||||
.remove(b'_')
|
||||
.remove(b'`')
|
||||
.remove(b'|')
|
||||
.remove(b'~');
|
||||
|
||||
pub(crate) enum PercentEncoding {
|
||||
PathSegment,
|
||||
@@ -463,7 +463,7 @@ impl PercentEncoding {
|
||||
percent_encoding::utf8_percent_encode(value, PATH_SEGMENT_ENCODE_SET).to_string()
|
||||
}
|
||||
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(),
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::io::{self, Cursor, Read};
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures::{try_ready, Future};
|
||||
use hyper::{self};
|
||||
use hyper;
|
||||
|
||||
use crate::async_impl;
|
||||
|
||||
|
||||
16
src/proxy.rs
16
src/proxy.rs
@@ -1,16 +1,16 @@
|
||||
use std::fmt;
|
||||
#[cfg(feature = "socks")]
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{IntoUrl, Url};
|
||||
use http::{header::HeaderValue, Uri};
|
||||
use hyper::client::connect::Destination;
|
||||
use percent_encoding::percent_decode;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::error::Error;
|
||||
use url::percent_encoding::percent_decode;
|
||||
#[cfg(target_os = "windows")]
|
||||
use winreg::enums::HKEY_CURRENT_USER;
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -326,12 +326,14 @@ impl ProxyScheme {
|
||||
// Resolve URL to a host and port
|
||||
#[cfg(feature = "socks")]
|
||||
let to_addr = || {
|
||||
let host_and_port = try_!(url.with_default_port(|url| match url.scheme() {
|
||||
"socks5" | "socks5h" => Ok(1080),
|
||||
_ => Err(()),
|
||||
let addrs = try_!(url.socket_addrs(|| match url.scheme() {
|
||||
"socks5" | "socks5h" => Some(1080),
|
||||
_ => None,
|
||||
}));
|
||||
let mut addr = try_!(host_and_port.to_socket_addrs());
|
||||
addr.next().ok_or_else(crate::error::unknown_proxy_scheme)
|
||||
addrs
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or_else(crate::error::unknown_proxy_scheme)
|
||||
};
|
||||
|
||||
let mut scheme = match url.scheme() {
|
||||
|
||||
Reference in New Issue
Block a user