@@ -18,7 +18,7 @@ use http_body_util::{Empty, Full, StreamBody};
18
18
use hyper:: body:: Bytes ;
19
19
use hyper:: body:: Frame ;
20
20
use hyper:: Request ;
21
- use hyper_util:: client:: legacy:: connect:: HttpConnector ;
21
+ use hyper_util:: client:: legacy:: connect:: { capture_connection , HttpConnector } ;
22
22
use hyper_util:: client:: legacy:: Client ;
23
23
use hyper_util:: rt:: { TokioExecutor , TokioIo } ;
24
24
@@ -876,3 +876,34 @@ fn alpn_h2() {
876
876
) ;
877
877
drop ( client) ;
878
878
}
879
+
880
+ #[ test]
881
+ fn capture_connection_on_client ( ) {
882
+ let _ = pretty_env_logger:: try_init ( ) ;
883
+
884
+ let rt = runtime ( ) ;
885
+ let connector = DebugConnector :: new ( ) ;
886
+
887
+ let client = Client :: builder ( TokioExecutor :: new ( ) ) . build ( connector) ;
888
+
889
+ let server = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
890
+ let addr = server. local_addr ( ) . unwrap ( ) ;
891
+ thread:: spawn ( move || {
892
+ let mut sock = server. accept ( ) . unwrap ( ) . 0 ;
893
+ //drop(server);
894
+ sock. set_read_timeout ( Some ( Duration :: from_secs ( 5 ) ) ) . unwrap ( ) ;
895
+ sock. set_write_timeout ( Some ( Duration :: from_secs ( 5 ) ) )
896
+ . unwrap ( ) ;
897
+ let mut buf = [ 0 ; 4096 ] ;
898
+ sock. read ( & mut buf) . expect ( "read 1" ) ;
899
+ sock. write_all ( b"HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n " )
900
+ . expect ( "write 1" ) ;
901
+ } ) ;
902
+ let mut req = Request :: builder ( )
903
+ . uri ( & * format ! ( "http://{}/a" , addr) )
904
+ . body ( Empty :: < Bytes > :: new ( ) )
905
+ . unwrap ( ) ;
906
+ let captured_conn = capture_connection ( & mut req) ;
907
+ rt. block_on ( client. request ( req) ) . expect ( "200 OK" ) ;
908
+ assert ! ( captured_conn. connection_metadata( ) . is_some( ) ) ;
909
+ }
0 commit comments