Skip to content

Commit bb38f55

Browse files
committed
add peer and local addr to Response as well
1 parent 8dfbc9a commit bb38f55

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ impl Request {
6060
}
6161
}
6262

63-
/// get the peer socket address for the underlying transport, if appropriate
63+
/// Get the peer socket address for the underlying transport, if appropriate
6464
pub fn peer_addr(&self) -> Option<SocketAddr> {
6565
self.peer_addr
6666
}
6767

68-
/// get the local socket address for the underlying transport, if appropriate
68+
/// Get the local socket address for the underlying transport, if appropriate
6969
pub fn local_addr(&self) -> Option<SocketAddr> {
7070
self.local_addr
7171
}

src/response.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use async_std::sync;
33

44
use std::convert::TryInto;
55
use std::mem;
6+
use std::net::SocketAddr;
67
use std::pin::Pin;
78
use std::task::{Context, Poll};
89

@@ -39,6 +40,8 @@ pin_project_lite::pin_project! {
3940
#[pin]
4041
body: Body,
4142
local: TypeMap,
43+
local_addr: Option<SocketAddr>,
44+
peer_addr: Option<SocketAddr>,
4245
}
4346
}
4447

@@ -54,6 +57,8 @@ impl Response {
5457
sender: Some(sender),
5558
receiver: Some(receiver),
5659
local: TypeMap::new(),
60+
peer_addr: None,
61+
local_addr: None,
5762
}
5863
}
5964

@@ -331,6 +336,16 @@ impl Response {
331336
self.version
332337
}
333338

339+
/// Get the peer socket address for the underlying transport, if appropriate
340+
pub fn peer_addr(&self) -> Option<SocketAddr> {
341+
self.peer_addr
342+
}
343+
344+
/// Get the local socket address for the underlying transport, if appropriate
345+
pub fn local_addr(&self) -> Option<SocketAddr> {
346+
self.local_addr
347+
}
348+
334349
/// Set the HTTP version.
335350
///
336351
/// # Examples
@@ -430,6 +445,8 @@ impl Clone for Response {
430445
receiver: self.receiver.clone(),
431446
body: Body::empty(),
432447
local: TypeMap::new(),
448+
peer_addr: self.peer_addr.clone(),
449+
local_addr: self.local_addr.clone(),
433450
}
434451
}
435452
}

0 commit comments

Comments
 (0)