Skip to content

Commit 8eb1be7

Browse files
committed
set peer and local addrs for h1 client
1 parent 3d1abe7 commit 8eb1be7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/h1.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ impl Clone for H1Client {
3232
impl HttpClient for H1Client {
3333
type Error = Error;
3434

35-
fn send(&self, req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
35+
fn send(&self, mut req: Request) -> BoxFuture<'static, Result<Response, Self::Error>> {
3636
Box::pin(async move {
3737
// Insert host
3838
let host = req
3939
.url()
4040
.host_str()
41-
.ok_or_else(|| Error::from_str(StatusCode::BadRequest, "missing hostname"))?;
41+
.ok_or_else(|| Error::from_str(StatusCode::BadRequest, "missing hostname"))?
42+
.to_string();
4243

4344
let scheme = req.url().scheme();
4445
if scheme != "http" && scheme != "https" {
@@ -64,10 +65,14 @@ impl HttpClient for H1Client {
6465
match scheme {
6566
"http" => {
6667
let stream = async_std::net::TcpStream::connect(addr).await?;
68+
req.set_peer_addr(stream.peer_addr().ok());
69+
req.set_local_addr(stream.local_addr().ok());
6770
client::connect(stream, req).await
6871
}
6972
"https" => {
7073
let raw_stream = async_std::net::TcpStream::connect(addr).await?;
74+
req.set_peer_addr(raw_stream.peer_addr().ok());
75+
req.set_local_addr(raw_stream.local_addr().ok());
7176

7277
let stream = async_native_tls::connect(host, raw_stream).await?;
7378

0 commit comments

Comments
 (0)