@@ -108,26 +108,34 @@ pub mod hyper {
108108 use http:: HeaderValue ;
109109 use http_body_util:: { BodyExt , Full } ;
110110 use hyper:: body:: { Body as HttpBody , Frame } ;
111- use hyper_util:: client:: legacy:: { connect:: HttpConnector , Client } ;
111+ use hyper_util:: client:: legacy:: {
112+ connect:: { Connect , HttpConnector } ,
113+ Client ,
114+ } ;
112115 use std:: fmt:: Debug ;
113116 use std:: pin:: Pin ;
114117 use std:: task:: { self , Poll } ;
115118 use std:: time:: Duration ;
116119 use tokio:: time;
117120
118121 #[ derive( Debug , Clone ) ]
119- pub struct HyperClient {
120- inner : Client < HttpConnector , Body > ,
122+ pub struct HyperClient < C = HttpConnector >
123+ where
124+ C : Connect + Clone + Send + Sync + ' static ,
125+ {
126+ inner : Client < C , Body > ,
121127 timeout : Duration ,
122128 authorization : Option < HeaderValue > ,
123129 }
124130
125- impl HyperClient {
131+ impl < C > HyperClient < C >
132+ where
133+ C : Connect + Clone + Send + Sync + ' static ,
134+ {
126135 /// Creates a new `HyperClient` with default `HttpConnector` and `TokioExecutor`.
127- pub fn new ( timeout : Duration , authorization : Option < HeaderValue > ) -> Self {
128- let connector = HttpConnector :: new ( ) ;
136+ pub fn new ( connector : C , timeout : Duration , authorization : Option < HeaderValue > ) -> Self {
137+ // TODO - support custom executor
129138 let inner = Client :: builder ( hyper_util:: rt:: TokioExecutor :: new ( ) ) . build ( connector) ;
130-
131139 Self {
132140 inner,
133141 timeout,
@@ -136,6 +144,16 @@ pub mod hyper {
136144 }
137145 }
138146
147+ impl HyperClient < HttpConnector > {
148+ /// Creates a new `HyperClient` with a default `HttpConnector`.
149+ pub fn with_default_connector (
150+ timeout : Duration ,
151+ authorization : Option < HeaderValue > ,
152+ ) -> Self {
153+ Self :: new ( HttpConnector :: new ( ) , timeout, authorization)
154+ }
155+ }
156+
139157 #[ async_trait]
140158 impl HttpClient for HyperClient {
141159 async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
0 commit comments