@@ -22,7 +22,7 @@ use http::{
22
22
use hyper:: {
23
23
body,
24
24
body:: HttpBody ,
25
- client:: { Client , HttpConnector } ,
25
+ client:: { connect :: Connect , Client , HttpConnector } ,
26
26
Body ,
27
27
} ;
28
28
use hyper_rustls:: HttpsConnector ;
@@ -99,8 +99,8 @@ impl AdapterOptions {
99
99
}
100
100
101
101
#[ derive( Clone ) ]
102
- pub struct Adapter {
103
- client : Arc < Client < HttpsConnector < HttpConnector > > > ,
102
+ pub struct Adapter < C > {
103
+ client : Arc < Client < C > > ,
104
104
healthcheck_url : Url ,
105
105
healthcheck_protocol : Protocol ,
106
106
async_init : bool ,
@@ -110,11 +110,11 @@ pub struct Adapter {
110
110
compression : bool ,
111
111
}
112
112
113
- impl Adapter {
114
- /// Create a new Adapter instance.
115
- /// This function initializes a new HTTP client
113
+ impl Adapter < HttpsConnector < HttpConnector > > {
114
+ /// Create a new HTTPS Adapter instance.
115
+ /// This function initializes a new HTTPS client
116
116
/// to talk with the web server.
117
- pub fn new ( options : & AdapterOptions ) -> Adapter {
117
+ pub fn new_https ( options : & AdapterOptions ) -> Adapter < HttpsConnector < HttpConnector > > {
118
118
if let Some ( cert_file) = & options. tls_cert_file {
119
119
env:: set_var ( "SSL_CERT_FILE" , cert_file) ;
120
120
}
@@ -133,10 +133,7 @@ impl Adapter {
133
133
134
134
let client = Client :: builder ( ) . pool_idle_timeout ( Duration :: from_secs ( 4 ) ) . build ( https) ;
135
135
136
- let schema = match options. enable_tls {
137
- true => "https" ,
138
- false => "http" ,
139
- } ;
136
+ let schema = "https" ;
140
137
141
138
let healthcheck_url = format ! (
142
139
"{}://{}:{}{}" ,
@@ -160,15 +157,47 @@ impl Adapter {
160
157
compression : options. compression ,
161
158
}
162
159
}
160
+ }
161
+
162
+ impl Adapter < HttpConnector > {
163
+ /// Create a new HTTP Adapter instance.
164
+ /// This function initializes a new HTTP client
165
+ /// to talk with the web server.
166
+ pub fn new ( options : & AdapterOptions ) -> Adapter < HttpConnector > {
167
+ let client = Client :: builder ( )
168
+ . pool_idle_timeout ( Duration :: from_secs ( 4 ) )
169
+ . build ( HttpConnector :: new ( ) ) ;
170
+
171
+ let schema = "http" ;
172
+
173
+ let healthcheck_url = format ! (
174
+ "{}://{}:{}{}" ,
175
+ schema, options. host, options. readiness_check_port, options. readiness_check_path
176
+ )
177
+ . parse ( )
178
+ . unwrap ( ) ;
179
+
180
+ let domain = format ! ( "{}://{}:{}" , schema, options. host, options. port)
181
+ . parse ( )
182
+ . unwrap ( ) ;
163
183
164
- /// Switch the default HTTP client with a different one.
165
- pub fn with_client ( self , client : Client < HttpsConnector < HttpConnector > > ) -> Self {
166
184
Adapter {
167
185
client : Arc :: new ( client) ,
168
- ..self
186
+ healthcheck_url,
187
+ healthcheck_protocol : options. readiness_check_protocol ,
188
+ domain,
189
+ base_path : options. base_path . clone ( ) ,
190
+ async_init : options. async_init ,
191
+ ready_at_init : Arc :: new ( AtomicBool :: new ( false ) ) ,
192
+ compression : options. compression ,
169
193
}
170
194
}
195
+ }
171
196
197
+ impl < C > Adapter < C >
198
+ where
199
+ C : Connect + Clone + Send + Sync + ' static ,
200
+ {
172
201
/// Register a Lambda Extension to ensure
173
202
/// that the adapter is loaded before any Lambda function
174
203
/// associated with it.
@@ -350,7 +379,10 @@ impl Adapter {
350
379
351
380
/// Implement a `Tower.Service` that sends the requests
352
381
/// to the web server.
353
- impl Service < Request > for Adapter {
382
+ impl < C > Service < Request > for Adapter < C >
383
+ where
384
+ C : Connect + Clone + Send + Sync + ' static ,
385
+ {
354
386
type Response = Response < Body > ;
355
387
type Error = Error ;
356
388
type Future = Pin < Box < dyn Future < Output = Result < Self :: Response , Self :: Error > > + Send > > ;
0 commit comments