Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http client): use https connector for https #750

Merged
merged 3 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions client/http-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,24 @@ impl HttpTransportClient {
return Err(Error::Url("Port number is missing in the URL".into()));
}

let mut connector = HttpConnector::new();

connector.set_reuse_address(true);
connector.set_nodelay(true);

let client = match target.scheme_str() {
Some("http") => {
let client = Client::builder().build::<_, hyper::Body>(connector);
HyperClient::Http(client)
}
Some("http") => HyperClient::Http(Client::new()),
#[cfg(feature = "tls")]
Some("https") => {
let connector = match cert_store {
CertificateStore::Native => hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.https_or_http()
.enable_http1()
.wrap_connector(connector),
.build(),
CertificateStore::WebPki => hyper_rustls::HttpsConnectorBuilder::new()
.with_webpki_roots()
.https_or_http()
.enable_http1()
.wrap_connector(connector),
.build(),
_ => return Err(Error::InvalidCertficateStore),
};
let client = Client::builder().build::<_, hyper::Body>(connector);
HyperClient::Https(client)
HyperClient::Https(Client::builder().build::<_, hyper::Body>(connector))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what the impact of this change is; was wrapping the HttpConnector causing an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see; I just read rustls/hyper-rustls#169. Interesting!

My reading/assumption was that the wrapping would work as we had expected!

}
_ => {
#[cfg(feature = "tls")]
Expand Down
6 changes: 2 additions & 4 deletions tests/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,15 @@ async fn http_making_more_requests_than_allowed_should_not_deadlock() {
}

#[tokio::test]
#[ignore]
async fn https_works() {
let client = HttpClientBuilder::default().build("https://kusama-rpc.polkadot.io").unwrap();
let client = HttpClientBuilder::default().build("https://kusama-rpc.polkadot.io:443").unwrap();
jsdw marked this conversation as resolved.
Show resolved Hide resolved
let response: String = client.request("system_chain", None).await.unwrap();
assert_eq!(&response, "Kusama");
}

#[tokio::test]
#[ignore]
async fn wss_works() {
let client = WsClientBuilder::default().build("wss://kusama-rpc.polkadot.io").await.unwrap();
let client = WsClientBuilder::default().build("wss://kusama-rpc.polkadot.io:443").await.unwrap();
let response: String = client.request("system_chain", None).await.unwrap();
assert_eq!(&response, "Kusama");
}
Expand Down