Skip to content

Commit 02c7214

Browse files
committed
add peer and local socket addrs to Request
1 parent b9129e4 commit 02c7214

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/request.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_std::io::{self, BufRead, Read};
22
use async_std::sync;
33

4+
use std::net::SocketAddr;
45
use std::convert::TryInto;
56
use std::mem;
67
use std::pin::Pin;
@@ -36,6 +37,8 @@ pin_project_lite::pin_project! {
3637
#[pin]
3738
body: Body,
3839
local: TypeMap,
40+
local_addr: Option<SocketAddr>,
41+
peer_addr: Option<SocketAddr>,
3942
}
4043
}
4144

@@ -52,9 +55,22 @@ impl Request {
5255
sender: Some(sender),
5356
receiver: Some(receiver),
5457
local: TypeMap::new(),
58+
peer_addr: None,
59+
local_addr: None,
5560
}
5661
}
5762

63+
/// get the peer socket address for the underlying transport, if appropriate
64+
pub fn peer_addr(&self) -> Option<SocketAddr> {
65+
self.peer_addr
66+
}
67+
68+
/// get the local socket address for the underlying transport, if appropriate
69+
pub fn local_addr(&self) -> Option<SocketAddr> {
70+
self.local_addr
71+
}
72+
73+
5874
/// Get the HTTP method
5975
pub fn method(&self) -> Method {
6076
self.method

0 commit comments

Comments
 (0)