@@ -18,7 +18,7 @@ use super::pool::{
18
18
#[ cfg( feature = "tcp" ) ]
19
19
use super :: HttpConnector ;
20
20
use crate :: body:: { Body , HttpBody } ;
21
- use crate :: common:: { exec:: BoxSendFuture , lazy as hyper_lazy, task, Future , Lazy , Pin , Poll } ;
21
+ use crate :: common:: { exec:: BoxSendFuture , sync_wrapper :: SyncWrapper , lazy as hyper_lazy, task, Future , Lazy , Pin , Poll } ;
22
22
use crate :: rt:: Executor ;
23
23
24
24
/// A Client to make outgoing HTTP requests.
@@ -45,7 +45,7 @@ struct Config {
45
45
/// This is returned by `Client::request` (and `Client::get`).
46
46
#[ must_use = "futures do nothing unless polled" ]
47
47
pub struct ResponseFuture {
48
- inner : Pin < Box < dyn Future < Output = crate :: Result < Response < Body > > > + Send > > ,
48
+ inner : SyncWrapper < Pin < Box < dyn Future < Output = crate :: Result < Response < Body > > > + Send > > > ,
49
49
}
50
50
51
51
// ===== impl Client =====
@@ -168,9 +168,9 @@ where
168
168
Version :: HTTP_10 => {
169
169
if is_http_connect {
170
170
warn ! ( "CONNECT is not allowed for HTTP/1.0" ) ;
171
- return ResponseFuture :: new ( Box :: pin ( future:: err (
171
+ return ResponseFuture :: new ( future:: err (
172
172
crate :: Error :: new_user_unsupported_request_method ( ) ,
173
- ) ) ) ;
173
+ ) ) ;
174
174
}
175
175
}
176
176
Version :: HTTP_2 => ( ) ,
@@ -181,11 +181,11 @@ where
181
181
let pool_key = match extract_domain ( req. uri_mut ( ) , is_http_connect) {
182
182
Ok ( s) => s,
183
183
Err ( err) => {
184
- return ResponseFuture :: new ( Box :: pin ( future:: err ( err) ) ) ;
184
+ return ResponseFuture :: new ( future:: err ( err) ) ;
185
185
}
186
186
} ;
187
187
188
- ResponseFuture :: new ( Box :: pin ( self . clone ( ) . retryably_send_request ( req, pool_key) ) )
188
+ ResponseFuture :: new ( self . clone ( ) . retryably_send_request ( req, pool_key) )
189
189
}
190
190
191
191
async fn retryably_send_request (
@@ -580,8 +580,13 @@ impl<C, B> fmt::Debug for Client<C, B> {
580
580
// ===== impl ResponseFuture =====
581
581
582
582
impl ResponseFuture {
583
- fn new ( fut : Pin < Box < dyn Future < Output = crate :: Result < Response < Body > > > + Send > > ) -> Self {
584
- Self { inner : fut }
583
+ fn new < F > ( value : F ) -> Self
584
+ where
585
+ F : Future < Output = crate :: Result < Response < Body > > > + Send + ' static ,
586
+ {
587
+ Self {
588
+ inner : SyncWrapper :: new ( Box :: pin ( value) )
589
+ }
585
590
}
586
591
587
592
fn error_version ( ver : Version ) -> Self {
@@ -602,7 +607,7 @@ impl Future for ResponseFuture {
602
607
type Output = crate :: Result < Response < Body > > ;
603
608
604
609
fn poll ( mut self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
605
- Pin :: new ( & mut self . inner ) . poll ( cx)
610
+ self . inner . get_mut ( ) . as_mut ( ) . poll ( cx)
606
611
}
607
612
}
608
613
@@ -1276,6 +1281,12 @@ impl fmt::Debug for Builder {
1276
1281
mod unit_tests {
1277
1282
use super :: * ;
1278
1283
1284
+ #[ test]
1285
+ fn response_future_is_sync ( ) {
1286
+ fn assert_sync < T : Sync > ( ) { }
1287
+ assert_sync :: < ResponseFuture > ( ) ;
1288
+ }
1289
+
1279
1290
#[ test]
1280
1291
fn set_relative_uri_with_implicit_path ( ) {
1281
1292
let mut uri = "http://hyper.rs" . parse ( ) . unwrap ( ) ;
0 commit comments