1818 */
1919//! HTTP transport and connection components
2020
21- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
21+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
2222use crate :: auth:: ClientCertificate ;
23- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
23+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
2424use crate :: cert:: CertificateValidation ;
2525use crate :: {
2626 auth:: Credentials ,
@@ -140,10 +140,13 @@ pub struct TransportBuilder {
140140 client_builder : reqwest:: ClientBuilder ,
141141 conn_pool : Box < dyn ConnectionPool > ,
142142 credentials : Option < Credentials > ,
143- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
143+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
144144 cert_validation : Option < CertificateValidation > ,
145+ #[ cfg( not( target_arch = "wasm32" ) ) ]
145146 proxy : Option < Url > ,
147+ #[ cfg( not( target_arch = "wasm32" ) ) ]
146148 proxy_credentials : Option < Credentials > ,
149+ #[ cfg( not( target_arch = "wasm32" ) ) ]
147150 disable_proxy : bool ,
148151 headers : HeaderMap ,
149152 meta_header : bool ,
@@ -161,10 +164,13 @@ impl TransportBuilder {
161164 client_builder : reqwest:: ClientBuilder :: new ( ) ,
162165 conn_pool : Box :: new ( conn_pool) ,
163166 credentials : None ,
164- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
167+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
165168 cert_validation : None ,
169+ #[ cfg( not( target_arch = "wasm32" ) ) ]
166170 proxy : None ,
171+ #[ cfg( not( target_arch = "wasm32" ) ) ]
167172 proxy_credentials : None ,
173+ #[ cfg( not( target_arch = "wasm32" ) ) ]
168174 disable_proxy : false ,
169175 headers : HeaderMap :: new ( ) ,
170176 meta_header : true ,
@@ -176,6 +182,7 @@ impl TransportBuilder {
176182 ///
177183 /// An optional username and password will be used to set the
178184 /// `Proxy-Authorization` header using Basic Authentication.
185+ #[ cfg( not( target_arch = "wasm32" ) ) ]
179186 pub fn proxy ( mut self , url : Url , username : Option < & str > , password : Option < & str > ) -> Self {
180187 self . proxy = Some ( url) ;
181188 if let Some ( u) = username {
@@ -189,6 +196,7 @@ impl TransportBuilder {
189196 /// Whether to disable proxies, including system proxies.
190197 ///
191198 /// NOTE: System proxies are enabled by default.
199+ #[ cfg( not( target_arch = "wasm32" ) ) ]
192200 pub fn disable_proxy ( mut self ) -> Self {
193201 self . disable_proxy = true ;
194202 self
@@ -203,7 +211,7 @@ impl TransportBuilder {
203211 /// Validation applied to the certificate provided to establish a HTTPS connection.
204212 /// By default, full validation is applied. When using a self-signed certificate,
205213 /// different validation can be applied.
206- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
214+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
207215 pub fn cert_validation ( mut self , validation : CertificateValidation ) -> Self {
208216 self . cert_validation = Some ( validation) ;
209217 self
@@ -254,11 +262,12 @@ impl TransportBuilder {
254262 client_builder = client_builder. default_headers ( self . headers ) ;
255263 }
256264
265+ #[ cfg( not( target_arch = "wasm32" ) ) ]
257266 if let Some ( t) = self . timeout {
258267 client_builder = client_builder. timeout ( t) ;
259268 }
260269
261- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
270+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
262271 {
263272 if let Some ( Credentials :: Certificate ( cert) ) = & self . credentials {
264273 client_builder = match cert {
@@ -280,7 +289,7 @@ impl TransportBuilder {
280289 } ;
281290 }
282291
283- #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
292+ #[ cfg( all ( any( feature = "native-tls" , feature = "rustls-tls" ) , not ( target_arch = "wasm32" ) ) ) ]
284293 if let Some ( v) = self . cert_validation {
285294 client_builder = match v {
286295 CertificateValidation :: Default => client_builder,
@@ -300,6 +309,7 @@ impl TransportBuilder {
300309 }
301310 }
302311
312+ #[ cfg( not( target_arch = "wasm32" ) ) ]
303313 if self . disable_proxy {
304314 client_builder = client_builder. no_proxy ( ) ;
305315 } else if let Some ( url) = self . proxy {
@@ -463,6 +473,7 @@ impl Transport {
463473 headers : HeaderMap ,
464474 query_string : Option < & Q > ,
465475 body : Option < B > ,
476+ #[ allow( unused_variables) ]
466477 timeout : Option < Duration > ,
467478 ) -> Result < reqwest:: RequestBuilder , Error >
468479 where
@@ -473,6 +484,7 @@ impl Transport {
473484 let url = connection. url . join ( path. trim_start_matches ( '/' ) ) ?;
474485 let mut request_builder = self . client . request ( reqwest_method, url) ;
475486
487+ #[ cfg( not( target_arch = "wasm32" ) ) ]
476488 if let Some ( t) = timeout {
477489 request_builder = request_builder. timeout ( t) ;
478490 }
@@ -482,7 +494,23 @@ impl Transport {
482494 // on a specific request, we want it to overwrite.
483495 if let Some ( c) = & self . credentials {
484496 request_builder = match c {
485- Credentials :: Basic ( u, p) => request_builder. basic_auth ( u, Some ( p) ) ,
497+ Credentials :: Basic ( u, p) => {
498+ #[ cfg( not( target_arch = "wasm32" ) ) ]
499+ {
500+ request_builder. basic_auth ( u, Some ( p) )
501+ }
502+ #[ cfg( target_arch = "wasm32" ) ]
503+ {
504+ // Missing basic_auth in the wasm32 target
505+ let mut header_value = b"Basic " . to_vec ( ) ;
506+ {
507+ let mut encoder = Base64Encoder :: new ( & mut header_value, base64:: STANDARD ) ;
508+ // The unwraps here are fine because Vec::write* is infallible.
509+ write ! ( encoder, "{}:{}" , u, p) . unwrap ( ) ;
510+ }
511+ request_builder. header ( reqwest:: header:: AUTHORIZATION , header_value)
512+ }
513+ } ,
486514 Credentials :: Bearer ( t) => request_builder. bearer_auth ( t) ,
487515 #[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
488516 Credentials :: Certificate ( _) => request_builder,
0 commit comments