@@ -131,15 +131,10 @@ impl ConnectorBuilder {
131131 self
132132 }
133133
134- /// Builds the connector with the provided TLS options configuration and optional layers.
134+ /// Builds the connector with the provided layers.
135135 pub fn build ( self , layers : Vec < BoxedConnectorLayer > ) -> crate :: Result < Connector > {
136136 let mut service = ConnectorService {
137- config : Config {
138- // The timeout is initially set to None and will be reassigned later
139- // based on the presence or absence of user-provided layers.
140- timeout : None ,
141- ..self . config
142- } ,
137+ config : self . config ,
143138 #[ cfg( feature = "socks" ) ]
144139 resolver : self . resolver . clone ( ) ,
145140 http : self . http ,
@@ -151,10 +146,12 @@ impl ConnectorBuilder {
151146
152147 // we have no user-provided layers, only use concrete types
153148 if layers. is_empty ( ) {
154- service. config . timeout = self . config . timeout ;
155149 return Ok ( Connector :: Simple ( service) ) ;
156150 }
157151
152+ // user-provided layers exist, the timeout will be applied as an additional layer.
153+ let timeout = service. config . timeout . take ( ) ;
154+
158155 // otherwise we have user provided layers
159156 // so we need type erasure all the way through
160157 // as well as mapping the unnameable type of the layers back to ConnectRequest for the
@@ -171,7 +168,7 @@ impl ConnectorBuilder {
171168 // now we handle the concrete stuff - any `connect_timeout`,
172169 // plus a final map_err layer we can use to cast default tower layer
173170 // errors to internal errors
174- match self . config . timeout {
171+ match timeout {
175172 Some ( timeout) => {
176173 let service = ServiceBuilder :: new ( )
177174 . layer ( TimeoutLayer :: new ( timeout) )
0 commit comments