|
0 |
From 0990b7914b589758ffab805854c5ef996b4ba316 Mon Sep 17 00:00:00 2001
|
|
1 |
From: Nikhil Benesch <nikhil.benesch@gmail.com>
|
|
2 |
Date: Tue, 30 Jul 2019 14:52:39 -0400
|
|
3 |
Subject: [PATCH] Upgrade to url v2.0
|
|
4 |
|
|
5 |
--- a/Cargo.toml
|
|
6 |
+++ b/Cargo.toml
|
|
7 |
@@ -33,7 +33,7 @@
|
|
8 |
version = "0.12.0"
|
|
9 |
|
|
10 |
[dependencies.cookie_store]
|
|
11 |
-version = "0.7.0"
|
|
12 |
+version = "0.8"
|
|
13 |
|
|
14 |
[dependencies.encoding_rs]
|
|
15 |
version = "0.8"
|
|
16 |
@@ -72,12 +72,15 @@
|
|
17 |
version = "0.3.7"
|
|
18 |
|
|
19 |
[dependencies.mime_guess]
|
|
20 |
-version = "2.0.0-alpha.6"
|
|
21 |
+version = "2.0.0"
|
|
22 |
|
|
23 |
[dependencies.native-tls]
|
|
24 |
version = "0.2"
|
|
25 |
optional = true
|
|
26 |
|
|
27 |
+[dependencies.percent-encoding]
|
|
28 |
+version = "2"
|
|
29 |
+
|
|
30 |
[dependencies.rustls]
|
|
31 |
version = "0.15"
|
|
32 |
features = ["dangerous_configuration"]
|
|
33 |
@@ -90,7 +93,7 @@
|
|
34 |
version = "1.0"
|
|
35 |
|
|
36 |
[dependencies.serde_urlencoded]
|
|
37 |
-version = "0.5"
|
|
38 |
+version = "0.6"
|
|
39 |
|
|
40 |
[dependencies.socks]
|
|
41 |
version = "0.3.2"
|
|
42 |
@@ -125,10 +128,10 @@
|
|
43 |
optional = true
|
|
44 |
|
|
45 |
[dependencies.url]
|
|
46 |
-version = "1.2"
|
|
47 |
+version = "2"
|
|
48 |
|
|
49 |
[dependencies.uuid]
|
|
50 |
-version = "0.7"
|
|
51 |
+version = "0.8"
|
|
52 |
features = ["v4"]
|
|
53 |
|
|
54 |
[dependencies.webpki-roots]
|
|
55 |
--- a/src/async_impl/multipart.rs
|
|
56 |
+++ b/src/async_impl/multipart.rs
|
|
57 |
@@ -3,7 +3,7 @@
|
|
58 |
use std::fmt;
|
|
59 |
|
|
60 |
use mime_guess::Mime;
|
|
61 |
-use url::percent_encoding::{self, EncodeSet, PATH_SEGMENT_ENCODE_SET};
|
|
62 |
+use percent_encoding::{self, AsciiSet};
|
|
63 |
use uuid::Uuid;
|
|
64 |
use http::HeaderMap;
|
|
65 |
|
|
66 |
@@ -371,31 +371,39 @@
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
-#[derive(Debug, Clone)]
|
|
71 |
-pub(crate) struct AttrCharEncodeSet;
|
|
72 |
+/// https://url.spec.whatwg.org/#fragment-percent-encode-set
|
|
73 |
+const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
|
|
74 |
|
|
75 |
-impl EncodeSet for AttrCharEncodeSet {
|
|
76 |
- fn contains(&self, ch: u8) -> bool {
|
|
77 |
- match ch as char {
|
|
78 |
- '!' => false,
|
|
79 |
- '#' => false,
|
|
80 |
- '$' => false,
|
|
81 |
- '&' => false,
|
|
82 |
- '+' => false,
|
|
83 |
- '-' => false,
|
|
84 |
- '.' => false,
|
|
85 |
- '^' => false,
|
|
86 |
- '_' => false,
|
|
87 |
- '`' => false,
|
|
88 |
- '|' => false,
|
|
89 |
- '~' => false,
|
|
90 |
- _ => {
|
|
91 |
- let is_alpha_numeric = ch >= 0x41 && ch <= 0x5a || ch >= 0x61 && ch <= 0x7a || ch >= 0x30 && ch <= 0x39;
|
|
92 |
- !is_alpha_numeric
|
|
93 |
- }
|
|
94 |
- }
|
|
95 |
- }
|
|
96 |
-}
|
|
97 |
+/// https://url.spec.whatwg.org/#path-percent-encode-set
|
|
98 |
+const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}');
|
|
99 |
+
|
|
100 |
+const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET.add(b'/').add(b'%');
|
|
101 |
+
|
|
102 |
+// This will be a bit shorter to express when AsciiSet.remove lands:
|
|
103 |
+// https://github.com/servo/rust-url/pull/528.
|
|
104 |
+/// https://tools.ietf.org/html/rfc8187#section-3.2.1
|
|
105 |
+const ATTR_CHAR_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
|
|
106 |
+ .add(b' ')
|
|
107 |
+ .add(b'"')
|
|
108 |
+ .add(b'%')
|
|
109 |
+ .add(b'\'')
|
|
110 |
+ .add(b'(')
|
|
111 |
+ .add(b')')
|
|
112 |
+ .add(b'*')
|
|
113 |
+ .add(b',')
|
|
114 |
+ .add(b'/')
|
|
115 |
+ .add(b':')
|
|
116 |
+ .add(b';')
|
|
117 |
+ .add(b'<')
|
|
118 |
+ .add(b'=')
|
|
119 |
+ .add(b'>')
|
|
120 |
+ .add(b'?')
|
|
121 |
+ .add(b'@')
|
|
122 |
+ .add(b'[')
|
|
123 |
+ .add(b'\\')
|
|
124 |
+ .add(b']')
|
|
125 |
+ .add(b'{')
|
|
126 |
+ .add(b'}');
|
|
127 |
|
|
128 |
pub(crate) enum PercentEncoding {
|
|
129 |
PathSegment,
|
|
130 |
@@ -443,7 +451,7 @@
|
|
131 |
.to_string()
|
|
132 |
},
|
|
133 |
PercentEncoding::AttrChar => {
|
|
134 |
- percent_encoding::utf8_percent_encode(value, AttrCharEncodeSet)
|
|
135 |
+ percent_encoding::utf8_percent_encode(value, ATTR_CHAR_ENCODE_SET)
|
|
136 |
.to_string()
|
|
137 |
},
|
|
138 |
PercentEncoding::NoOp => { value.to_string() },
|
|
139 |
--- a/src/lib.rs
|
|
140 |
+++ b/src/lib.rs
|
|
141 |
@@ -193,6 +193,7 @@
|
|
142 |
extern crate mime_guess;
|
|
143 |
#[cfg(feature = "default-tls")]
|
|
144 |
extern crate native_tls;
|
|
145 |
+extern crate percent_encoding;
|
|
146 |
extern crate serde;
|
|
147 |
extern crate serde_json;
|
|
148 |
extern crate serde_urlencoded;
|
|
149 |
--- a/src/proxy.rs
|
|
150 |
+++ b/src/proxy.rs
|
|
151 |
@@ -5,10 +5,12 @@
|
|
152 |
|
|
153 |
use http::{header::HeaderValue, Uri};
|
|
154 |
use hyper::client::connect::Destination;
|
|
155 |
-use url::percent_encoding::percent_decode;
|
|
156 |
+use percent_encoding::percent_decode;
|
|
157 |
use {IntoUrl, Url};
|
|
158 |
use std::collections::HashMap;
|
|
159 |
use std::env;
|
|
160 |
+#[cfg(feature = "socks")]
|
|
161 |
+use std::io;
|
|
162 |
#[cfg(target_os = "windows")]
|
|
163 |
use std::error::Error;
|
|
164 |
#[cfg(target_os = "windows")]
|
|
165 |
@@ -330,11 +332,15 @@
|
|
166 |
// Resolve URL to a host and port
|
|
167 |
#[cfg(feature = "socks")]
|
|
168 |
let to_addr = || {
|
|
169 |
- let host_and_port = try_!(url.with_default_port(|url| match url.scheme() {
|
|
170 |
- "socks5" | "socks5h" => Ok(1080),
|
|
171 |
- _ => Err(())
|
|
172 |
- }));
|
|
173 |
- let mut addr = try_!(host_and_port.to_socket_addrs());
|
|
174 |
+ let host = try_!(url.host_str().ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "URL has no host")));
|
|
175 |
+ let port = try_!(match url.port_or_known_default() {
|
|
176 |
+ Some(port) => Ok(port),
|
|
177 |
+ None => match url.scheme() {
|
|
178 |
+ "socks5" | "socks5h" => Ok(1080),
|
|
179 |
+ _ => Err(io::Error::new(io::ErrorKind::InvalidData, "URL has no port")),
|
|
180 |
+ }
|
|
181 |
+ });
|
|
182 |
+ let mut addr = try_!(format!("{}:{}", host, port).to_socket_addrs());
|
|
183 |
addr
|
|
184 |
.next()
|
|
185 |
.ok_or_else(::error::unknown_proxy_scheme)
|