@@ -15,7 +15,7 @@ use serde::Serialize;
1515 feature = "brotli" ,
1616 feature = "deflate" ,
1717) ) ]
18- use super :: layer:: { config:: RequestAcceptEncoding , decoder :: AcceptEncoding } ;
18+ use super :: layer:: config:: RequestAcceptEncoding ;
1919#[ cfg( feature = "multipart" ) ]
2020use super :: multipart;
2121use super :: {
@@ -29,14 +29,13 @@ use super::{
2929use crate :: {
3030 EmulationFactory , Error , Method , OriginalHeaders , Proxy , Url ,
3131 core:: {
32- client:: { connect :: TcpConnectOptions , options:: TransportOptions } ,
32+ client:: options:: TransportOptions ,
3333 ext:: {
34- RequestConfig , RequestEnforcedHttpVersion , RequestOriginalHeaders , RequestProxyMatcher ,
35- RequestTcpConnectOptions , RequestTransportOptions ,
34+ RequestConfig , RequestConfigValue , RequestEnforcedHttpVersion , RequestOriginalHeaders ,
35+ RequestProxyMatcher , RequestTcpConnectOptions , RequestTransportOptions ,
3636 } ,
3737 } ,
3838 header:: { CONTENT_TYPE , HeaderMap , HeaderName , HeaderValue } ,
39- proxy:: Matcher as ProxyMatcher ,
4039 redirect,
4140} ;
4241
@@ -107,18 +106,6 @@ impl Request {
107106 & mut self . headers
108107 }
109108
110- /// Get a mutable reference to the original headers.
111- #[ inline]
112- pub fn original_headers_mut ( & mut self ) -> & mut Option < OriginalHeaders > {
113- RequestConfig :: < RequestOriginalHeaders > :: get_mut ( & mut self . extensions )
114- }
115-
116- /// Get a mutable reference to the redirect policy.
117- #[ inline]
118- pub fn redirect_mut ( & mut self ) -> & mut Option < redirect:: Policy > {
119- RequestConfig :: < RequestRedirectPolicy > :: get_mut ( & mut self . extensions )
120- }
121-
122109 /// Get the body.
123110 #[ inline]
124111 pub fn body ( & self ) -> Option < & Body > {
@@ -140,55 +127,13 @@ impl Request {
140127 /// Get a mutable reference to the http version.
141128 #[ inline]
142129 pub fn version_mut ( & mut self ) -> & mut Option < Version > {
143- RequestConfig :: < RequestEnforcedHttpVersion > :: get_mut ( & mut self . extensions )
144- }
145-
146- /// Get a mutable reference to the timeout.
147- #[ inline]
148- pub fn timeout_mut ( & mut self ) -> & mut Option < Duration > {
149- RequestConfig :: < RequestTotalTimeout > :: get_mut ( & mut self . extensions )
150- }
151-
152- /// Get a mutable reference to the read timeout.
153- #[ inline]
154- pub fn read_timeout_mut ( & mut self ) -> & mut Option < Duration > {
155- RequestConfig :: < RequestReadTimeout > :: get_mut ( & mut self . extensions )
156- }
157-
158- /// Get a mutable reference to the tcp connect options.
159- #[ inline]
160- pub ( crate ) fn tcp_connect_options_mut ( & mut self ) -> & mut Option < TcpConnectOptions > {
161- RequestConfig :: < RequestTcpConnectOptions > :: get_mut ( & mut self . extensions )
162- }
163-
164- /// Get a mutable reference to the proxy matcher.
165- #[ inline]
166- pub ( crate ) fn proxy_matcher_mut ( & mut self ) -> & mut Option < ProxyMatcher > {
167- RequestConfig :: < RequestProxyMatcher > :: get_mut ( & mut self . extensions )
168- }
169-
170- /// Get the accepts encoding.
171- #[ cfg( any(
172- feature = "gzip" ,
173- feature = "zstd" ,
174- feature = "brotli" ,
175- feature = "deflate" ,
176- ) ) ]
177- #[ inline]
178- pub ( crate ) fn accpet_encoding_mut ( & mut self ) -> & mut Option < AcceptEncoding > {
179- RequestConfig :: < RequestAcceptEncoding > :: get_mut ( & mut self . extensions )
180- }
181-
182- /// Skip client default headers.
183- #[ inline]
184- pub ( crate ) fn default_headers_mut ( & mut self ) -> & mut Option < bool > {
185- RequestConfig :: < RequestSkipDefaultHeaders > :: get_mut ( & mut self . extensions )
130+ self . config_mut :: < RequestEnforcedHttpVersion > ( )
186131 }
187132
188- // Get a mutable reference to the transport options .
133+ /// Get a mutable reference to the request config value .
189134 #[ inline]
190- pub ( crate ) fn transport_options_mut ( & mut self ) -> & mut Option < TransportOptions > {
191- RequestConfig :: < RequestTransportOptions > :: get_mut ( & mut self . extensions )
135+ pub ( crate ) fn config_mut < T : RequestConfigValue > ( & mut self ) -> & mut Option < T :: Value > {
136+ RequestConfig :: < T > :: get_mut ( & mut self . extensions )
192137 }
193138
194139 /// Get the extensions.
@@ -336,15 +281,15 @@ impl RequestBuilder {
336281 /// Set the original headers for this request.
337282 pub fn original_headers ( mut self , original_headers : OriginalHeaders ) -> RequestBuilder {
338283 if let Ok ( ref mut req) = self . request {
339- * req. original_headers_mut ( ) = Some ( original_headers) ;
284+ * req. config_mut :: < RequestOriginalHeaders > ( ) = Some ( original_headers) ;
340285 }
341286 self
342287 }
343288
344289 /// Set skip client default headers for this request.
345290 pub fn default_headers ( mut self , skip : bool ) -> RequestBuilder {
346291 if let Ok ( ref mut req) = self . request {
347- * req. default_headers_mut ( ) = Some ( skip) ;
292+ * req. config_mut :: < RequestSkipDefaultHeaders > ( ) = Some ( skip) ;
348293 }
349294 self
350295 }
@@ -419,7 +364,7 @@ impl RequestBuilder {
419364 /// the timeout configured using `ClientBuilder::timeout()`.
420365 pub fn timeout ( mut self , timeout : Duration ) -> RequestBuilder {
421366 if let Ok ( ref mut req) = self . request {
422- * req. timeout_mut ( ) = Some ( timeout) ;
367+ * req. config_mut :: < RequestTotalTimeout > ( ) = Some ( timeout) ;
423368 }
424369 self
425370 }
@@ -431,7 +376,7 @@ impl RequestBuilder {
431376 /// overrides the read timeout configured using `ClientBuilder::read_timeout()`.
432377 pub fn read_timeout ( mut self , timeout : Duration ) -> RequestBuilder {
433378 if let Ok ( ref mut req) = self . request {
434- * req. read_timeout_mut ( ) = Some ( timeout) ;
379+ * req. config_mut :: < RequestReadTimeout > ( ) = Some ( timeout) ;
435380 }
436381 self
437382 }
@@ -524,7 +469,7 @@ impl RequestBuilder {
524469 /// Set the redirect policy for this request.
525470 pub fn redirect ( mut self , policy : redirect:: Policy ) -> RequestBuilder {
526471 if let Ok ( ref mut req) = self . request {
527- * req. redirect_mut ( ) = Some ( policy) ;
472+ * req. config_mut :: < RequestRedirectPolicy > ( ) = Some ( policy) ;
528473 }
529474 self
530475 }
@@ -533,8 +478,9 @@ impl RequestBuilder {
533478 #[ cfg( feature = "gzip" ) ]
534479 pub fn gzip ( mut self , gzip : bool ) -> RequestBuilder {
535480 if let Ok ( ref mut req) = self . request {
536- let accept_encoding = req. accpet_encoding_mut ( ) . get_or_insert_default ( ) ;
537- accept_encoding. gzip ( gzip) ;
481+ req. config_mut :: < RequestAcceptEncoding > ( )
482+ . get_or_insert_default ( )
483+ . gzip ( gzip) ;
538484 }
539485 self
540486 }
@@ -543,8 +489,9 @@ impl RequestBuilder {
543489 #[ cfg( feature = "brotli" ) ]
544490 pub fn brotli ( mut self , brotli : bool ) -> RequestBuilder {
545491 if let Ok ( ref mut req) = self . request {
546- let accept_encoding = req. accpet_encoding_mut ( ) . get_or_insert_default ( ) ;
547- accept_encoding. brotli ( brotli) ;
492+ req. config_mut :: < RequestAcceptEncoding > ( )
493+ . get_or_insert_default ( )
494+ . brotli ( brotli) ;
548495 }
549496 self
550497 }
@@ -553,8 +500,9 @@ impl RequestBuilder {
553500 #[ cfg( feature = "deflate" ) ]
554501 pub fn deflate ( mut self , deflate : bool ) -> RequestBuilder {
555502 if let Ok ( ref mut req) = self . request {
556- let accept_encoding = req. accpet_encoding_mut ( ) . get_or_insert_default ( ) ;
557- accept_encoding. deflate ( deflate) ;
503+ req. config_mut :: < RequestAcceptEncoding > ( )
504+ . get_or_insert_default ( )
505+ . deflate ( deflate) ;
558506 }
559507 self
560508 }
@@ -563,8 +511,9 @@ impl RequestBuilder {
563511 #[ cfg( feature = "zstd" ) ]
564512 pub fn zstd ( mut self , zstd : bool ) -> RequestBuilder {
565513 if let Ok ( ref mut req) = self . request {
566- let accept_encoding = req. accpet_encoding_mut ( ) . get_or_insert_default ( ) ;
567- accept_encoding. zstd ( zstd) ;
514+ req. config_mut :: < RequestAcceptEncoding > ( )
515+ . get_or_insert_default ( )
516+ . zstd ( zstd) ;
568517 }
569518 self
570519 }
@@ -590,7 +539,7 @@ impl RequestBuilder {
590539 /// ```
591540 pub fn proxy ( mut self , proxy : Proxy ) -> RequestBuilder {
592541 if let Ok ( ref mut req) = self . request {
593- * req. proxy_matcher_mut ( ) = Some ( proxy. into_matcher ( ) ) ;
542+ * req. config_mut :: < RequestProxyMatcher > ( ) = Some ( proxy. into_matcher ( ) ) ;
594543 }
595544 self
596545 }
@@ -601,8 +550,9 @@ impl RequestBuilder {
601550 V : Into < Option < IpAddr > > ,
602551 {
603552 if let Ok ( ref mut req) = self . request {
604- let tcp_connect_options = req. tcp_connect_options_mut ( ) . get_or_insert_default ( ) ;
605- tcp_connect_options. set_local_address ( local_address. into ( ) ) ;
553+ req. config_mut :: < RequestTcpConnectOptions > ( )
554+ . get_or_insert_default ( )
555+ . set_local_address ( local_address. into ( ) ) ;
606556 }
607557 self
608558 }
@@ -614,8 +564,9 @@ impl RequestBuilder {
614564 V6 : Into < Option < Ipv6Addr > > ,
615565 {
616566 if let Ok ( ref mut req) = self . request {
617- let tcp_connect_options = req. tcp_connect_options_mut ( ) . get_or_insert_default ( ) ;
618- tcp_connect_options. set_local_addresses ( ipv4. into ( ) , ipv6. into ( ) ) ;
567+ req. config_mut :: < RequestTcpConnectOptions > ( )
568+ . get_or_insert_default ( )
569+ . set_local_addresses ( ipv4. into ( ) , ipv6. into ( ) ) ;
619570 }
620571 self
621572 }
@@ -638,8 +589,9 @@ impl RequestBuilder {
638589 I : Into < std:: borrow:: Cow < ' static , str > > ,
639590 {
640591 if let Ok ( ref mut req) = self . request {
641- let tcp_connect_options = req. tcp_connect_options_mut ( ) . get_or_insert_default ( ) ;
642- tcp_connect_options. set_interface ( interface. into ( ) ) ;
592+ req. config_mut :: < RequestTcpConnectOptions > ( )
593+ . get_or_insert_default ( )
594+ . set_interface ( interface. into ( ) ) ;
643595 }
644596 self
645597 }
@@ -661,7 +613,7 @@ impl RequestBuilder {
661613 if let Some ( ( tls_opts, http1_opts, http2_opts) ) =
662614 transport_opts. map ( TransportOptions :: into_parts)
663615 {
664- req. transport_options_mut ( )
616+ req. config_mut :: < RequestTransportOptions > ( )
665617 . get_or_insert_default ( )
666618 . http1_options ( http1_opts)
667619 . http2_options ( http2_opts)
0 commit comments