Skip to content

Commit

Permalink
feat: added suport to http crate 1.0 (#508)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Dec 6, 2023
1 parent 923a443 commit 1945fa0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions actix-tls/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Added support to `http` crate version `1.0`.

## 3.1.1

- Fix `rustls` v0.21 version requirement.
Expand Down
3 changes: 2 additions & 1 deletion actix-tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
17 changes: 15 additions & 2 deletions actix-tls/src/connect/uri.rs
Original file line number Diff line number Diff line change
@@ -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("")
}
Expand Down
17 changes: 17 additions & 0 deletions actix-tls/tests/test_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1945fa0

Please sign in to comment.