@@ -76,6 +76,7 @@ pub struct TransportBuilder {
76
76
conn_pool : Box < dyn ConnectionPool > ,
77
77
credentials : Option < Credentials > ,
78
78
proxy : Option < Url > ,
79
+ proxy_credentials : Option < Credentials > ,
79
80
disable_proxy : bool ,
80
81
}
81
82
@@ -91,17 +92,28 @@ impl TransportBuilder {
91
92
conn_pool : Box :: new ( conn_pool) ,
92
93
credentials : None ,
93
94
proxy : None ,
95
+ proxy_credentials : None ,
94
96
disable_proxy : false ,
95
97
}
96
98
}
97
99
98
- /// Configures a proxy
99
- pub fn proxy ( mut self , url : Url ) -> Self {
100
+ /// Configures a proxy.
101
+ ///
102
+ /// An optional username and password will be used to set the
103
+ /// `Proxy-Authorization` header using Basic Authentication.
104
+ pub fn proxy ( mut self , url : Url , username : Option < & str > , password : Option < & str > ) -> Self {
100
105
self . proxy = Some ( url) ;
106
+ if let Some ( u) = username {
107
+ let p = password. unwrap_or ( "" ) ;
108
+ self . proxy_credentials = Some ( Credentials :: Basic ( u. into ( ) , p. into ( ) ) ) ;
109
+ }
110
+
101
111
self
102
112
}
103
113
104
- /// Whether to disable proxies, including system proxies
114
+ /// Whether to disable proxies, including system proxies.
115
+ ///
116
+ /// NOTE: System proxies are enabled by default.
105
117
pub fn disable_proxy ( mut self ) -> Self {
106
118
self . disable_proxy = true ;
107
119
self
@@ -130,10 +142,14 @@ impl TransportBuilder {
130
142
if self . disable_proxy {
131
143
client_builder = client_builder. no_proxy ( ) ;
132
144
} else if let Some ( url) = self . proxy {
133
- client_builder = match url. scheme ( ) {
134
- "https" => client_builder. proxy ( reqwest:: Proxy :: https ( url) ?) ,
135
- _ => client_builder. proxy ( reqwest:: Proxy :: http ( url) ?) ,
136
- } ;
145
+ let mut proxy = reqwest:: Proxy :: all ( url) ?;
146
+ if let Some ( c) = self . proxy_credentials {
147
+ proxy = match c {
148
+ Credentials :: Basic ( u, p) => proxy. basic_auth ( & u, & p) ,
149
+ _ => proxy,
150
+ } ;
151
+ }
152
+ client_builder = client_builder. proxy ( proxy) ;
137
153
}
138
154
139
155
let client = client_builder. build ( ) ?;
0 commit comments