1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +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:
morenol 2023-12-05 20:18:17 -04:00 committed by GitHub
parent 923a443950
commit 1945fa0675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View File

@ -2,6 +2,8 @@
## Unreleased ## Unreleased
- Added support to `http` crate version `1.0`.
## 3.1.1 ## 3.1.1
- Fix `rustls` v0.21 version requirement. - Fix `rustls` v0.21 version requirement.

View File

@ -56,7 +56,7 @@ rustls-0_21 = ["tokio-rustls-024", "webpki-roots-025"]
native-tls = ["tokio-native-tls"] native-tls = ["tokio-native-tls"]
# support http::Uri as connect address # support http::Uri as connect address
uri = ["http"] uri = ["http", "http-1"]
[dependencies] [dependencies]
actix-rt = { version = "2.2", default-features = false } actix-rt = { version = "2.2", default-features = false }
@ -72,6 +72,7 @@ tracing = { version = "0.1.30", default-features = false, features = ["log"] }
# uri # uri
http = { version = "0.2.3", optional = true } http = { version = "0.2.3", optional = true }
http-1 = { package = "http", version = "1", optional = true }
# openssl # openssl
tls-openssl = { package = "openssl", version = "0.10.55", optional = true } tls-openssl = { package = "openssl", version = "0.10.55", optional = true }

View File

@ -1,8 +1,21 @@
use http::Uri; use http as http_02;
use super::Host; 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 { fn hostname(&self) -> &str {
self.host().unwrap_or("") self.host().unwrap_or("")
} }

View File

@ -114,6 +114,23 @@ async fn test_openssl_uri() {
assert_eq!(con.peer_addr().unwrap(), srv.addr()); 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"))] #[cfg(all(feature = "rustls-0_21", feature = "uri"))]
#[actix_rt::test] #[actix_rt::test]
async fn test_rustls_uri() { async fn test_rustls_uri() {