1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 23:17:43 +02:00

add local_addr binding to connector service

This commit is contained in:
fakeshadow
2021-02-24 01:13:17 +08:00
parent 8d74cf387d
commit c3be839a69
4 changed files with 98 additions and 12 deletions

View File

@ -1,4 +1,7 @@
use std::io;
use std::{
io,
net::{IpAddr, Ipv4Addr},
};
use actix_codec::{BytesCodec, Framed};
use actix_rt::net::TcpStream;
@ -125,3 +128,25 @@ async fn test_rustls_uri() {
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[actix_rt::test]
async fn test_local_addr() {
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let conn = actix_connect::default_connector();
let local = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 3));
let (con, _) = conn
.call(Connect::with_addr("10", srv.addr()).set_local_addr(local))
.await
.unwrap()
.into_parts();
assert_eq!(con.local_addr().unwrap().ip(), local)
}