Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Determine proxy parameters for a URL from the environment.
2 //
3 // Copyright (c) 2016 Ivan Nejgebauer <[email protected]>
4 //
5 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
6 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
7 // http://opensource.org/licenses/MIT>, at your option. This file may not be
8 // copied, modified, or distributed except according to those terms.
9 //!
10 //! Environment variables are one way to request the use of an HTTP proxy server for
11 //! outgoing connections in many command-line applications. _Which_ environment variable
12 //! will be used depends on the target URL and the convention used by the application
13 //! (or, customarily, the connection library that it uses.)
14 //!
15 //! This crate aims to replicate the convention of the __curl__ library and offer it
16 //! behind a simple API: in most cases, a single function, `for_url()`, which accepts
17 //! a target URL and returns the proxy parameters, if applicable. The method for determining
18 //! the parameters is described in detail in that function's documentation.
19 //!
20 //! # Getting Started
21 //!
22 //! Add the following to the `[dependencies]` section of your `Cargo.toml`:
23 //!
24 //! ```toml
25 //! env_proxy = "0.3"
26 //! ```
27 //!
28 //! If you're using the 2015 edition of Rust, import the crate to your crate root:
29 //!
30 //! ```
31 //! extern crate env_proxy;
32 //! ```
33 //!
34 //! # Examples
35 //!
36 //! To determine proxy parameters for `http://www.example.org`:
37 //!
38 //! ```
39 //! # extern crate url;
40 //! # extern crate env_proxy;
41 //! # fn main() {
42 //! use env_proxy;
43 //! use url::Url;
44 //!
45 //! let url = Url::parse("http://www.example.org").unwrap();
46 //! if let Some(proxy) = env_proxy::for_url(&url).host_port() {
47 //! println!("Proxy host: {}", proxy.0);
48 //! println!("Proxy port: {}", proxy.1);
49 //! }
50 //! # }
51 //! ```
52
53
54 #[cfg(test)]
55 use lazy_staticrust-analyzer cargo lazy_static 1.5.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!;
56 use logrust-analyzer cargo log 0.4.34 crate/::warnrust-analyzer cargo log 0.4.34 macros/warn!;
57
58 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().;
59 use urlrust-analyzer cargo url 2.5.8 crate/::{selfrust-analyzer cargo url 2.5.8 crate/, Urlrust-analyzer cargo url 2.5.8 Url#};
60
61 macro_rules! env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair! {
62 ($lc_var:expr, $uc_var:expr) => {
63 var_os($lc_var).or_else(|| var_os($uc_var))
64 .map(|v| v.to_str()
65 .map(str::to_string)
66 .or_else(|| {
67 warn!("non UTF-8 content in {}/{}", $lc_var, $uc_var);
68 None
69 }))
70 .unwrap_or_else(|| None)
71 };
72 }
73
74 fn matches_no_proxyrust-analyzer cargo env_proxy 0.4.1 matches_no_proxy().(url: &Urlrust-analyzer cargo url 2.5.8 Url#) -> bool {
75 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(no_proxy) = env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair!!("no_proxy", "NO_PROXY") {
76 if no_proxy rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."*" {
77 return true;
78 }
79 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(host) = url.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_str().() {
80 'elems: for elem in no_proxy.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().',' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ') {
81 if elem rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."" || elem rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."." {
82 continue;
83 }
84 let ch1 = elem.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
85 let mut elem_iter = elem.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().();
86 if ch1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.' {
87 elem_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().();
88 }
89 let mut elem_iter = elem_iter.revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().();
90 let mut host_iter = host.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().();
91 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elem_ch) = elem_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/rev/impl#[`Rev<I>`][Iterator]next().() {
92 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(host_ch) = host_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/rev/impl#[`Rev<I>`][Iterator]next().() {
93 let host_ch = host_ch as u32;
94 let elem_ch = match elem_ch as u32 {
95 uppercase @ 0x41 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#0x5a => uppercase rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().0x20,
96 anything => anything
97 };
98 if elem_ch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().host_ch {
99 continue;
100 }
101 continue 'elems;
102 } else {
103 continue 'elems;
104 }
105 }
106 match host_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/rev/impl#[`Rev<I>`][Iterator]next().() {
107 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return true,
108 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(host_ch) if host_ch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.' => return true,
109 _ => ()
110 }
111 }
112 }
113 }
114 false
115 }
116
117 /// A wrapper for the proxy URL retrieved from the environment.
118 ///
119 /// This struct will wrap the raw value of the URL, which is only guaranteed to be valid UTF-8
120 /// when returned. Various methods exist to extract the value as-is, translate it into other forms,
121 /// and provide elements of interest.
122 pub struct ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>);
123
124 impl ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl# {
125 /// Return the raw value of the proxy URL.
126 pub fn raw_valuerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]raw_value().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
127 self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0.
128 }
129
130 /// Return `true` if the `None` value is wrapped.
131 pub fn is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().(self) -> bool {
132 self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
133 }
134
135 /// Set the default port to use when transforming the raw URL value if
136 /// the port isn't specified in the URL.
137 ///
138 /// A `ProxyUrl` instance returned by the library will have the default
139 /// port set to __8080__, which corresponds to __http-alt__ in the IANA port
140 /// registry. This is different from __curl__, which uses port 1080 as the default.
141 ///
142 /// To skip the default port substitution, use [`with_no_default_port()`]
143 /// (#method.with_no_default_port) on the instance.
144 pub fn with_default_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]with_default_port().(self, port: u16) -> Selfrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl] {
145 ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(port))
146 }
147
148 /// Don't use the default port value when transforming the raw URL.
149 pub fn with_no_default_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]with_no_default_port().(self) -> Selfrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl] {
150 ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
151 }
152
153 /// Transform the raw proxy URL into a `Url`.
154 ///
155 /// The transformation will:
156 ///
157 /// * Parse the raw URL as a `Url`. If the raw URL lacks the scheme, `http` is assumed and
158 /// "http://" is prepended to canonicalize the value;
159 /// * Ensure that the host part is not empty;
160 /// * Use the default value for the port (or not, see [`with_default_port()`](#method.with_default_port))
161 /// if one is not specified in the raw URL.
162 /// * Ensure that the port is not empty.
163 ///
164 /// If any of the steps fail, `None` will be returned.
165 pub fn to_urlrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_url().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Urlrust-analyzer cargo url 2.5.8 Url#> {
166 let mut orig_scheme = self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s|
167 if s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("http://") {
168 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http")
169 } else if s.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("https://") {
170 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("https")
171 } else {
172 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
173 }
174 ).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
175 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mut url)) = self.0rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#0..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|mut s| {
176 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("://") {
177 s.insert_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]insert_str().(0, "http://");
178 orig_scheme = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http");
179 }
180 if orig_scheme.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
181 s = s.replacenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replacen().("http", "xttp", 1);
182 }
183 Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(&s).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| {
184 warnrust-analyzer cargo log 0.4.34 macros/warn!!("url parse error: {}", e);
185 e
186 })
187 }) {
188 if url.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_str().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
189 warnrust-analyzer cargo log 0.4.34 macros/warn!!("host part of the URL is empty");
190 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
191 }
192 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(orig_scheme) = orig_scheme {
193 let port = url.portrust-analyzer cargo url 2.5.8 impl#[Url]port().();
194 url = match formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", orig_scheme, &url[rust-analyzer cargo url 2.5.8 slicing/impl#[Url][`Index<RangeFrom<Position>>`]index().urlrust-analyzer cargo url 2.5.8 crate/::Positionrust-analyzer cargo url 2.5.8 slicing/Position#::AfterSchemerust-analyzer cargo url 2.5.8 slicing/Position#AfterScheme#..]rust-analyzer cargo url 2.5.8 slicing/impl#[Url][`Index<RangeFrom<Position>>`]index().).parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() {
195 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(url) => url,
196 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
197 warnrust-analyzer cargo log 0.4.34 macros/warn!!("could not set URL scheme back to {}: {}", orig_scheme, e);
198 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
199 },
200 };
201 if port.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
202 url.set_portrust-analyzer cargo url 2.5.8 impl#[Url]set_port().(port).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(());
203 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(url);
204 }
205 }
206 if url.portrust-analyzer cargo url 2.5.8 impl#[Url]port().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
207 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(url);
208 } else if self.1rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#1..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
209 warnrust-analyzer cargo log 0.4.34 macros/warn!!("the port of the URL is unknown");
210 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
211 }
212 match url.set_portrust-analyzer cargo url 2.5.8 impl#[Url]set_port().(self.1rust-analyzer cargo env_proxy 0.4.1 ProxyUrl#1.) {
213 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(url),
214 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => warnrust-analyzer cargo log 0.4.34 macros/warn!!("could not set URL port"),
215 }
216 }
217 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
218 }
219
220 /// Return the __(host, port)__ tuple of the proxy.
221 ///
222 /// The raw URL will first be transformed into a `Url`, with any errors in the conversion
223 /// producing a `None` (see [`to_url()`](#method.to_url)).
224 pub fn host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u16)> {
225 self.to_urlrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_url().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|u| (u.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_str().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("host_str").to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), u.port_or_known_defaultrust-analyzer cargo url 2.5.8 impl#[Url]port_or_known_default().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("port")))
226 }
227
228
229 /// Return the string representation of the proxy URL.
230 ///
231 /// The raw URL will first be transformed into a `Url`, with any errors in the conversion
232 /// producing a `None` (see [`to_url()`](#method.to_url)).
233 pub fn to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
234 self.to_urlrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_url().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Urlrust-analyzer cargo url 2.5.8 Url#::into_stringrust-analyzer cargo url 2.5.8 impl#[Url]into_string().)
235 }
236 }
237
238 /// Determine proxy parameters for a URL by examining the environment variables.
239 ///
240 /// __Attention__: in a multithreaded program, care should be taken not to change the environment
241 /// in multiple threads simultaneously without some form of serialization.
242 ///
243 /// Most environment variables described here can be defined either with an all-lowercase or an
244 /// all-uppercase name. If both versions are defined, the all-lowercase name takes precedence
245 /// (e.g., __no_proxy__ will be used even if __NO_PROXY__ is defined.) The only exception is
246 /// __http_proxy__, where only the lowercase name is checked for. This text will use the
247 /// lowercase variants for simplicity.
248 ///
249 /// If __no_proxy__ is defined, check the host part of the URL against its components and return
250 /// `None` if there is any match. The value of __no_proxy__ should be a space- or comma-separated
251 /// list of host/domain names or IP addresses for which no proxying should be done, or a single
252 /// '&#8239;__*__&#8239;' (asterisk) which means that proxying is disabled for all hosts. Empty names
253 /// are skipped. Names beginning with a dot are not treated specially; matching is always done
254 /// by full domain name component. A name consisting of a bare dot is skipped (this is different
255 /// from __curl__'s behavior.)
256 ///
257 /// The rules are summarized in the following table, where the two rightmost columns are headed by two
258 /// __no_proxy__ components, the leftmost column contains hostnames, and the symbol inside each cell
259 /// represents the result of checking the hostname against the corresponding component:
260 ///
261 /// | |example.org|.example.org|
262 /// |-------------|:---------:|:----------:|
263 /// |example.org | &#x2714; | &#x2714; |
264 /// |a.example.org| &#x2714; | &#x2714; |
265 /// |xample.org | &#x2718; | &#x2718; |
266 /// |org | &#x2718; | &#x2718; |
267 ///
268 /// For the __ftp__ protocol scheme, __ftp_proxy__ is checked first; for __http__, __http_proxy__
269 /// is checked, and for __https__, it's __https_proxy__. These three schemes will fall back to __all_proxy__
270 /// if the original variable is undefined. For all other schemes only __all_proxy__ is checked. In this
271 /// context, "checked" means that the value of a variable is used if present, and the search for further
272 /// definitions stops.
273 ///
274 /// The return value, if not `None`, is an opaque structure wrapping the value (possibly canonicalized,
275 /// see [`ProxyUrl::to_url()`](struct.ProxyUrl.html#method.to_url)) of the chosen environment variable.
276 ///
277 /// If the target URL matches __no_proxy__, or if the hostname cannot be extracted from the URL,
278 /// the function returns `None`. If the port is not explicitly defined in the proxy URL, the value 8080
279 /// is used.
280 pub fn for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(url: &Urlrust-analyzer cargo url 2.5.8 Url#) -> ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl# {
281 if matches_no_proxyrust-analyzer cargo env_proxy 0.4.1 matches_no_proxy().(url) {
282 return ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
283 }
284
285 let maybe_https_proxy = env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair!!("https_proxy", "HTTPS_PROXY");
286 let maybe_ftp_proxy = env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair!!("ftp_proxy", "FTP_PROXY");
287 let maybe_http_proxy = env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair!!("http_proxy", ""); // ugh, but it works
288 let maybe_all_proxy = env_var_pairrust-analyzer cargo env_proxy 0.4.1 env_var_pair!!("all_proxy", "ALL_PROXY");
289
290 let url_value = match url.schemerust-analyzer cargo url 2.5.8 impl#[Url]scheme().() {
291 "https" => maybe_https_proxy.orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(maybe_all_proxy),
292 "http" => maybe_http_proxy.orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(maybe_all_proxy),
293 "ftp" => maybe_ftp_proxy.orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(maybe_all_proxy),
294 _ => maybe_all_proxy,
295 };
296 ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(url_value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(8080))
297 }
298
299 /// Determine proxy parameters for a URL given as a string.
300 ///
301 /// Convert the given string to a URL and pass it to [`for_url()`](#method.for_url), returning
302 /// its result. If the conversion of the input argument fails, return `None`.
303 pub fn for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>>(s: S) -> ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl# {
304 let url = match Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(s.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) {
305 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(url) => url,
306 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
307 warnrust-analyzer cargo log 0.4.34 macros/warn!!("error parsing '{}' as Url: {}", s.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), e);
308 return ProxyUrlrust-analyzer cargo env_proxy 0.4.1 ProxyUrl#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
309 },
310 };
311 for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&url)
312 }
313
314 #[cfg(test)]
315 mod testsrust-analyzer cargo env_proxy 0.4.1 tests/ {
316 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::{remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var()., set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().};
317 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#;
318 use superrust-analyzer cargo env_proxy 0.4.1 crate/::*;
319 use urlrust-analyzer cargo url 2.5.8 crate/::Urlrust-analyzer cargo url 2.5.8 Url#;
320
321 // environment is per-process, and we need it stable per-thread,
322 // hence locking
323 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
324 static ref LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK#: Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#<()> = Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(());
325 }
326
327 fn scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().() {
328 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("http_proxy");
329 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("https_proxy");
330 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("HTTPS_PROXY");
331 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("ftp_proxy");
332 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("FTP_PROXY");
333 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("all_proxy");
334 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("ALL_PROXY");
335 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("no_proxy");
336 remove_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/remove_var().("NO_PROXY");
337 }
338
339 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
340 fn no_proxy_simple_namerust-analyzer cargo env_proxy 0.4.1 tests/no_proxy_simple_name().() {
341 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
342 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
343 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("no_proxy", "example.org");
344 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
345 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
346 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
347 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://example.org").is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
348 }
349
350 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
351 fn no_proxy_globalrust-analyzer cargo env_proxy 0.4.1 tests/no_proxy_global().() {
352 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
353 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
354 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("no_proxy", "*");
355 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
356 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
357 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
358 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://example.org").is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
359 }
360
361 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
362 fn no_proxy_subdomainrust-analyzer cargo env_proxy 0.4.1 tests/no_proxy_subdomain().() {
363 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
364 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
365 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("no_proxy", "example.org");
366 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
367 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
368 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
369 }
370
371 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
372 fn no_proxy_subdomain_dotrust-analyzer cargo env_proxy 0.4.1 tests/no_proxy_subdomain_dot().() {
373 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
374 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
375 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("no_proxy", ".example.org");
376 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
377 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
378 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
379 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
380 }
381
382 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
383 fn no_proxy_multiple_listrust-analyzer cargo env_proxy 0.4.1 tests/no_proxy_multiple_list().() {
384 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
385 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
386 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("no_proxy", "com, .example.org, net");
387 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
388 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
389 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
390 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").is_nonerust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]is_none().());
391 }
392
393 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
394 fn http_proxy_specificrust-analyzer cargo env_proxy 0.4.1 tests/http_proxy_specific().() {
395 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
396 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
397 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:8080");
398 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8081");
399 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
400 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
401 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
402 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
403 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8080/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
404 );
405 }
406
407 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
408 fn default_proxy_url_schemerust-analyzer cargo env_proxy 0.4.1 tests/default_proxy_url_scheme().() {
409 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
410 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
411 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "proxy.example.com:8080");
412 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
413 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
414 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
415 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
416 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8080/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
417 );
418 }
419
420 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
421 fn proxy_url_with_explicit_scheme_portrust-analyzer cargo env_proxy 0.4.1 tests/proxy_url_with_explicit_scheme_port().() {
422 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
423 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
424 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com:80");
425 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
426 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 80)));
427 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
428 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
429 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
430 );
431 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "https://proxy.example.com:443");
432 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 443)));
433 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
434 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
435 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("https://proxy.example.com/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
436 );
437 }
438
439 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
440 fn proxy_url_without_portrust-analyzer cargo env_proxy 0.4.1 tests/proxy_url_without_port().() {
441 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
442 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
443 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("http_proxy", "http://proxy.example.com");
444 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
445 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
446 }
447
448 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
449 fn http_proxy_fallbackrust-analyzer cargo env_proxy 0.4.1 tests/http_proxy_fallback().() {
450 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
451 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
452 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("ALL_PROXY", "http://proxy.example.com:8080");
453 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
454 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
455 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
456 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
457 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8080/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
458 );
459 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8081");
460 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.org".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8081)));
461 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
462 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("http://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
463 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.org:8081/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
464 );
465 }
466
467 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
468 fn https_proxy_specificrust-analyzer cargo env_proxy 0.4.1 tests/https_proxy_specific().() {
469 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
470 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
471 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("HTTPS_PROXY", "http://proxy.example.com:8080");
472 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8081");
473 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("https://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
474 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
475 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
476 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("https://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
477 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8080/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
478 );
479 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("https_proxy", "http://proxy.example.com:8082");
480 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8082)));
481 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
482 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("https://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
483 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8082/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
484 );
485 }
486
487 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
488 fn https_proxy_fallbackrust-analyzer cargo env_proxy 0.4.1 tests/https_proxy_fallback().() {
489 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
490 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
491 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("ALL_PROXY", "http://proxy.example.org:8081");
492 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("ftp://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
493 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.org".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8081)));
494 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
495 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("https://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
496 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.org:8081/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
497 );
498 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8082");
499 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.org".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8082)));
500 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
501 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("https://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
502 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.org:8082/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
503 );
504 }
505
506 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
507 fn ftp_proxy_specificrust-analyzer cargo env_proxy 0.4.1 tests/ftp_proxy_specific().() {
508 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
509 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
510 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("FTP_PROXY", "http://proxy.example.com:8080");
511 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8081");
512 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("ftp://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
513 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8080)));
514 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
515 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("ftp://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
516 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8080/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
517 );
518 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("ftp_proxy", "http://proxy.example.com:8082");
519 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.com".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8082)));
520 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
521 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("ftp://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
522 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.com:8082/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
523 );
524 }
525
526 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
527 fn ftp_proxy_fallbackrust-analyzer cargo env_proxy 0.4.1 tests/ftp_proxy_fallback().() {
528 let _l = LOCKrust-analyzer cargo env_proxy 0.4.1 tests/LOCK..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().();
529 scrub_envrust-analyzer cargo env_proxy 0.4.1 tests/scrub_env().();
530 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("ALL_PROXY", "http://proxy.example.org:8081");
531 let u = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("ftp://www.example.org").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
532 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.org".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8081)));
533 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
534 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("ftp://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
535 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.org:8081/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
536 );
537 set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("all_proxy", "http://proxy.example.org:8082");
538 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(for_urlrust-analyzer cargo env_proxy 0.4.1 for_url().(&u).host_portrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]host_port().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(("proxy.example.org".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 8082)));
539 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
540 for_url_strrust-analyzer cargo env_proxy 0.4.1 for_url_str().("ftp://www.example.org").to_stringrust-analyzer cargo env_proxy 0.4.1 impl#[ProxyUrl]to_string().(),
541 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("http://proxy.example.org:8082/".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
542 );
543 }
544 }