Skip to content

Commit

Permalink
fix(http client): use https connector for https (#750)
Browse files Browse the repository at this point in the history
* fix: use https conn for https

* enable integration tests for https and wss

* remove socket options of http client
  • Loading branch information
niklasad1 authored May 3, 2022
1 parent 8e945de commit 661870a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
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))
}
_ => {
#[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();
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

0 comments on commit 661870a

Please sign in to comment.