mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 16:52:58 +01:00
feat: added suport to http
crate 1.0
(#508)
* chore: use same feature * test: add test for new http version added * stylistic review --------- Co-authored-by: Luis Moreno <morenol@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
923a443950
commit
1945fa0675
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Added support to `http` crate version `1.0`.
|
||||
|
||||
## 3.1.1
|
||||
|
||||
- Fix `rustls` v0.21 version requirement.
|
||||
|
@ -56,7 +56,7 @@ rustls-0_21 = ["tokio-rustls-024", "webpki-roots-025"]
|
||||
native-tls = ["tokio-native-tls"]
|
||||
|
||||
# support http::Uri as connect address
|
||||
uri = ["http"]
|
||||
uri = ["http", "http-1"]
|
||||
|
||||
[dependencies]
|
||||
actix-rt = { version = "2.2", default-features = false }
|
||||
@ -72,6 +72,7 @@ tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
||||
# uri
|
||||
http = { version = "0.2.3", optional = true }
|
||||
http-1 = { package = "http", version = "1", optional = true }
|
||||
|
||||
# openssl
|
||||
tls-openssl = { package = "openssl", version = "0.10.55", optional = true }
|
||||
|
@ -1,8 +1,21 @@
|
||||
use http::Uri;
|
||||
use http as http_02;
|
||||
|
||||
use super::Host;
|
||||
|
||||
impl Host for Uri {
|
||||
impl Host for http_02::Uri {
|
||||
fn hostname(&self) -> &str {
|
||||
self.host().unwrap_or("")
|
||||
}
|
||||
|
||||
fn port(&self) -> Option<u16> {
|
||||
match self.port_u16() {
|
||||
Some(port) => Some(port),
|
||||
None => scheme_to_port(self.scheme_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Host for http_1::Uri {
|
||||
fn hostname(&self) -> &str {
|
||||
self.host().unwrap_or("")
|
||||
}
|
||||
|
@ -114,6 +114,23 @@ async fn test_openssl_uri() {
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "rustls-0_21", feature = "uri"))]
|
||||
#[actix_rt::test]
|
||||
async fn test_rustls_uri_http1() {
|
||||
let srv = TestServer::start(|| {
|
||||
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 = Connector::default().service();
|
||||
let addr = http_1::Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
|
||||
let con = conn.call(addr.into()).await.unwrap();
|
||||
assert_eq!(con.peer_addr().unwrap(), srv.addr());
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "rustls-0_21", feature = "uri"))]
|
||||
#[actix_rt::test]
|
||||
async fn test_rustls_uri() {
|
||||
|
Loading…
Reference in New Issue
Block a user