File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,18 @@ impl<State> Request<State> {
309309 pub fn is_empty ( & self ) -> Option < bool > {
310310 Some ( self . request . len ( ) ? == 0 )
311311 }
312+
313+ /// Peer address of the underlying transport
314+ #[ must_use]
315+ pub fn peer_addr ( & self ) -> Option < & str > {
316+ self . request . peer_addr ( )
317+ }
318+
319+ /// Local address of the underlying transport
320+ #[ must_use]
321+ pub fn local_addr ( & self ) -> Option < & str > {
322+ self . request . local_addr ( )
323+ }
312324}
313325
314326impl < State > AsMut < http:: Request > for Request < State > {
Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ fn hello_world() -> Result<(), http_types::Error> {
1212 let port = test_utils:: find_port ( ) . await ;
1313 let server = task:: spawn ( async move {
1414 let mut app = tide:: new ( ) ;
15- app. at ( "/" ) . get ( |mut req : Request < ( ) > | async move {
15+ app. at ( "/" ) . get ( move |mut req : Request < ( ) > | async move {
1616 assert_eq ! ( req. body_string( ) . await . unwrap( ) , "nori" . to_string( ) ) ;
17+ assert ! ( req. local_addr( ) . unwrap( ) . contains( & port. to_string( ) ) ) ;
18+ assert ! ( req. peer_addr( ) . is_some( ) ) ;
1719 let res = Response :: new ( StatusCode :: Ok ) . body_string ( "says hello" . to_string ( ) ) ;
1820 Ok ( res)
1921 } ) ;
You can’t perform that action at this time.
0 commit comments