Codebase list rust-stfu8 / 1890576
Port reqwest to url 2 Andrej Shadura 4 years ago
2 changed file(s) with 173 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11
22 * Package reqwest 0.9.19 from crates.io using debcargo 2.2.10
33
4 -- Andrej Shadura <andrewsh@debian.org> Mon, 12 Aug 2019 17:46:49 +0200
4 -- Andrej Shadura <andrewsh@debian.org> Tue, 13 Aug 2019 13:44:56 +0200
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
05 --- a/Cargo.toml
16 +++ b/Cargo.toml
2 @@ -72,7 +72,7 @@
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 @@
317 version = "0.3.7"
418
519 [dependencies.mime_guess]
822
923 [dependencies.native-tls]
1024 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,7 +128,7 @@
43 optional = true
44
45 [dependencies.url]
46 -version = "1.2"
47 +version = "2"
48
49 [dependencies.uuid]
50 version = "0.7"
51 --- a/src/async_impl/multipart.rs
52 +++ b/src/async_impl/multipart.rs
53 @@ -3,7 +3,7 @@
54 use std::fmt;
55
56 use mime_guess::Mime;
57 -use url::percent_encoding::{self, EncodeSet, PATH_SEGMENT_ENCODE_SET};
58 +use percent_encoding::{self, AsciiSet};
59 use uuid::Uuid;
60 use http::HeaderMap;
61
62 @@ -371,31 +371,39 @@
63 }
64 }
65
66 -#[derive(Debug, Clone)]
67 -pub(crate) struct AttrCharEncodeSet;
68 +/// https://url.spec.whatwg.org/#fragment-percent-encode-set
69 +const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
70
71 -impl EncodeSet for AttrCharEncodeSet {
72 - fn contains(&self, ch: u8) -> bool {
73 - match ch as char {
74 - '!' => false,
75 - '#' => false,
76 - '$' => false,
77 - '&' => false,
78 - '+' => false,
79 - '-' => false,
80 - '.' => false,
81 - '^' => false,
82 - '_' => false,
83 - '`' => false,
84 - '|' => false,
85 - '~' => false,
86 - _ => {
87 - let is_alpha_numeric = ch >= 0x41 && ch <= 0x5a || ch >= 0x61 && ch <= 0x7a || ch >= 0x30 && ch <= 0x39;
88 - !is_alpha_numeric
89 - }
90 - }
91 - }
92 -}
93 +/// https://url.spec.whatwg.org/#path-percent-encode-set
94 +const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'#').add(b'?').add(b'{').add(b'}');
95 +
96 +const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET.add(b'/').add(b'%');
97 +
98 +// This will be a bit shorter to express when AsciiSet.remove lands:
99 +// https://github.com/servo/rust-url/pull/528.
100 +/// https://tools.ietf.org/html/rfc8187#section-3.2.1
101 +const ATTR_CHAR_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
102 + .add(b' ')
103 + .add(b'"')
104 + .add(b'%')
105 + .add(b'\'')
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
124 pub(crate) enum PercentEncoding {
125 PathSegment,
126 @@ -443,7 +451,7 @@
127 .to_string()
128 },
129 PercentEncoding::AttrChar => {
130 - percent_encoding::utf8_percent_encode(value, AttrCharEncodeSet)
131 + percent_encoding::utf8_percent_encode(value, ATTR_CHAR_ENCODE_SET)
132 .to_string()
133 },
134 PercentEncoding::NoOp => { value.to_string() },
135 --- a/src/lib.rs
136 +++ b/src/lib.rs
137 @@ -193,6 +193,7 @@
138 extern crate mime_guess;
139 #[cfg(feature = "default-tls")]
140 extern crate native_tls;
141 +extern crate percent_encoding;
142 extern crate serde;
143 extern crate serde_json;
144 extern crate serde_urlencoded;
145 --- a/src/proxy.rs
146 +++ b/src/proxy.rs
147 @@ -5,10 +5,12 @@
148
149 use http::{header::HeaderValue, Uri};
150 use hyper::client::connect::Destination;
151 -use url::percent_encoding::percent_decode;
152 +use percent_encoding::percent_decode;
153 use {IntoUrl, Url};
154 use std::collections::HashMap;
155 use std::env;
156 +#[cfg(feature = "socks")]
157 +use std::io;
158 #[cfg(target_os = "windows")]
159 use std::error::Error;
160 #[cfg(target_os = "windows")]
161 @@ -330,11 +332,15 @@
162 // Resolve URL to a host and port
163 #[cfg(feature = "socks")]
164 let to_addr = || {
165 - let host_and_port = try_!(url.with_default_port(|url| match url.scheme() {
166 - "socks5" | "socks5h" => Ok(1080),
167 - _ => Err(())
168 - }));
169 - let mut addr = try_!(host_and_port.to_socket_addrs());
170 + let host = try_!(url.host_str().ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "URL has no host")));
171 + let port = try_!(match url.port_or_known_default() {
172 + Some(port) => Ok(port),
173 + None => match url.scheme() {
174 + "socks5" | "socks5h" => Ok(1080),
175 + _ => Err(io::Error::new(io::ErrorKind::InvalidData, "URL has no port")),
176 + }
177 + });
178 + let mut addr = try_!(format!("{}:{}", host, port).to_socket_addrs());
179 addr
180 .next()
181 .ok_or_else(::error::unknown_proxy_scheme)