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> {
309
309
pub fn is_empty ( & self ) -> Option < bool > {
310
310
Some ( self . request . len ( ) ? == 0 )
311
311
}
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
+ }
312
324
}
313
325
314
326
impl < 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> {
12
12
let port = test_utils:: find_port ( ) . await ;
13
13
let server = task:: spawn ( async move {
14
14
let mut app = tide:: new ( ) ;
15
- app. at ( "/" ) . get ( |mut req : Request < ( ) > | async move {
15
+ app. at ( "/" ) . get ( move |mut req : Request < ( ) > | async move {
16
16
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( ) ) ;
17
19
let res = Response :: new ( StatusCode :: Ok ) . body_string ( "says hello" . to_string ( ) ) ;
18
20
Ok ( res)
19
21
} ) ;
You can’t perform that action at this time.
0 commit comments