@@ -1325,6 +1325,7 @@ test! {
1325
1325
}
1326
1326
1327
1327
mod conn {
1328
+ use std:: error:: Error ;
1328
1329
use std:: io:: { self , Read , Write } ;
1329
1330
use std:: net:: { SocketAddr , TcpListener } ;
1330
1331
use std:: pin:: Pin ;
@@ -1333,15 +1334,15 @@ mod conn {
1333
1334
use std:: time:: Duration ;
1334
1335
1335
1336
use bytes:: { Buf , Bytes } ;
1336
- use futures_channel:: oneshot;
1337
+ use futures_channel:: { mpsc , oneshot} ;
1337
1338
use futures_util:: future:: { self , poll_fn, FutureExt , TryFutureExt } ;
1338
- use http_body_util:: Empty ;
1339
- use hyper:: upgrade:: OnUpgrade ;
1339
+ use http_body_util:: { Empty , StreamBody } ;
1340
1340
use tokio:: io:: { AsyncRead , AsyncReadExt as _, AsyncWrite , AsyncWriteExt as _, ReadBuf } ;
1341
1341
use tokio:: net:: { TcpListener as TkTcpListener , TcpStream } ;
1342
1342
1343
1343
use hyper:: body:: HttpBody ;
1344
1344
use hyper:: client:: conn;
1345
+ use hyper:: upgrade:: OnUpgrade ;
1345
1346
use hyper:: { self , Method , Recv , Request , Response , StatusCode } ;
1346
1347
1347
1348
use super :: { concat, s, support, tcp_connect, FutureHyperExt } ;
@@ -1524,17 +1525,23 @@ mod conn {
1524
1525
1525
1526
rt. spawn ( conn. map_err ( |e| panic ! ( "conn error: {}" , e) ) . map ( |_| ( ) ) ) ;
1526
1527
1527
- let ( mut sender, body) = Recv :: channel ( ) ;
1528
+ let ( mut sender, recv) = mpsc:: channel :: < Result < Bytes , Box < dyn Error + Send + Sync > > > ( 0 ) ;
1529
+
1528
1530
let sender = thread:: spawn ( move || {
1529
- sender. try_send_data ( "hello" . into ( ) ) . expect ( "try_send_data" ) ;
1531
+ sender. try_send ( Ok ( "hello" . into ( ) ) ) . expect ( "try_send_data" ) ;
1530
1532
support:: runtime ( ) . block_on ( rx) . unwrap ( ) ;
1531
- sender. abort ( ) ;
1533
+
1534
+ // Aborts the body in an abnormal fashion.
1535
+ let _ = sender. try_send ( Err ( Box :: new ( std:: io:: Error :: new (
1536
+ io:: ErrorKind :: Other ,
1537
+ "body write aborted" ,
1538
+ ) ) ) ) ;
1532
1539
} ) ;
1533
1540
1534
1541
let req = Request :: builder ( )
1535
1542
. method ( Method :: POST )
1536
1543
. uri ( "/" )
1537
- . body ( body )
1544
+ . body ( StreamBody :: new ( recv ) )
1538
1545
. unwrap ( ) ;
1539
1546
let res = client. send_request ( req) ;
1540
1547
rt. block_on ( res) . unwrap_err ( ) ;
@@ -2111,7 +2118,7 @@ mod conn {
2111
2118
. http2_only ( true )
2112
2119
. http2_keep_alive_interval ( Duration :: from_secs ( 1 ) )
2113
2120
. http2_keep_alive_timeout ( Duration :: from_secs ( 1 ) )
2114
- . handshake :: < _ , Recv > ( io)
2121
+ . handshake ( io)
2115
2122
. await
2116
2123
. expect ( "http handshake" ) ;
2117
2124
@@ -2120,9 +2127,10 @@ mod conn {
2120
2127
} ) ;
2121
2128
2122
2129
// Use a channel to keep request stream open
2123
- let ( _tx, body) = hyper:: Recv :: channel ( ) ;
2124
- let req1 = http:: Request :: new ( body) ;
2125
- let _resp = client. send_request ( req1) . await . expect ( "send_request" ) ;
2130
+ let ( _tx, recv) = mpsc:: channel :: < Result < Bytes , Box < dyn Error + Send + Sync > > > ( 0 ) ;
2131
+ let req = http:: Request :: new ( StreamBody :: new ( recv) ) ;
2132
+
2133
+ let _resp = client. send_request ( req) . await . expect ( "send_request" ) ;
2126
2134
2127
2135
// sleep longer than keepalive would trigger
2128
2136
tokio:: time:: sleep ( Duration :: from_secs ( 4 ) ) . await ;
0 commit comments