@@ -108,47 +108,53 @@ 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:: Connect , 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 < C > {
122+ pub struct HyperClient < C = HttpConnector >
123+ where
124+ C : Connect + Clone + Send + Sync + ' static ,
125+ {
120126 inner : Client < C , Body > ,
121127 timeout : Duration ,
122128 authorization : Option < HeaderValue > ,
123129 }
124130
125- impl < C > HyperClient < C > {
126- pub fn new_with_timeout ( inner : Client < C , Body > , timeout : Duration ) -> Self {
131+ impl < C > HyperClient < C >
132+ where
133+ C : Connect + Clone + Send + Sync + ' static ,
134+ {
135+ pub fn new ( connector : C , timeout : Duration , authorization : Option < HeaderValue > ) -> Self {
136+ // TODO - support custom executor
137+ let inner = Client :: builder ( hyper_util:: rt:: TokioExecutor :: new ( ) ) . build ( connector) ;
127138 Self {
128139 inner,
129140 timeout,
130- authorization : None ,
141+ authorization,
131142 }
132143 }
144+ }
133145
134- pub fn new_with_timeout_and_authorization_header (
135- inner : Client < C , Body > ,
146+ impl HyperClient < HttpConnector > {
147+ /// Creates a new `HyperClient` with a default `HttpConnector`.
148+ pub fn with_default_connector (
136149 timeout : Duration ,
137- authorization : HeaderValue ,
150+ authorization : Option < HeaderValue > ,
138151 ) -> Self {
139- Self {
140- inner,
141- timeout,
142- authorization : Some ( authorization) ,
143- }
152+ Self :: new ( HttpConnector :: new ( ) , timeout, authorization)
144153 }
145154 }
146155
147156 #[ async_trait]
148- impl < C > HttpClient for HyperClient < C >
149- where
150- C : Connect + Send + Sync + Clone + Debug + ' static ,
151- {
157+ impl HttpClient for HyperClient {
152158 async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
153159 let ( parts, body) = request. into_parts ( ) ;
154160 let mut request = Request :: from_parts ( parts, Body ( Full :: from ( body) ) ) ;
0 commit comments