Skip to content

Commit

Permalink
Use hyper-rustls remove hyper-tls for client. (#643)
Browse files Browse the repository at this point in the history
* Use `hyper-rustls` remove `hyper-tls` for client.

* cargo clippy
  • Loading branch information
chrislearn committed Jan 15, 2024
1 parent 8d039ec commit 37b619c
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ hmac = "0.12"
hex = "0.4"
hostname-validator = "1"
hyper = { version = "1", features = ["full"] }
hyper-rustls = "0.26"
hyper-util = { version = "0.1.2", default-features = true }
hyper-tls = "0.6"
indexmap = "2"
inventory = "0.3"
jsonwebtoken = "9.1"
Expand Down
4 changes: 2 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ native-tls = ["http1", "http2", "dep:tokio-native-tls", "dep:native-tls"]
openssl = ["http2", "dep:openssl", "dep:tokio-openssl"]
unix = ["http1"]
test = ["dep:brotli", "dep:flate2", "dep:zstd", "dep:encoding_rs", "dep:serde_urlencoded", "dep:url", "tokio/macros"]
acme = ["http1", "http2", "hyper-util/http1", "hyper-util/http2","hyper-util/client-legacy", "dep:hyper-tls", "dep:rcgen", "dep:ring", "dep:x509-parser", "dep:tokio-rustls", "dep:rustls-pemfile"]
acme = ["http1", "http2", "hyper-util/http1", "hyper-util/http2","hyper-util/client-legacy", "dep:hyper-rustls", "dep:rcgen", "dep:ring", "dep:x509-parser", "dep:tokio-rustls", "dep:rustls-pemfile"]
tower-compat = ["dep:tower"]

[dependencies]
Expand Down Expand Up @@ -70,7 +70,7 @@ ring = { workspace = true, optional = true }
rustls-pemfile = { workspace = true, optional = true }
salvo-http3 = { workspace = true, optional = true, features = ["quinn"] }
salvo_macros = { workspace = true }
hyper-tls = { workspace = true, optional = true }
hyper-rustls = { workspace = true, optional = true }
hyper-util = { workspace = true, features = ["tokio"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
Expand Down
10 changes: 8 additions & 2 deletions crates/core/src/conn/acme/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use base64::engine::{general_purpose::URL_SAFE_NO_PAD, Engine};
use bytes::Bytes;
use http_body_util::{BodyExt, Full};
use hyper::Uri;
use hyper_tls::HttpsConnector;
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use hyper_util::rt::TokioExecutor;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -46,7 +46,13 @@ pub(crate) struct AcmeClient {
impl AcmeClient {
#[inline]
pub(crate) async fn new(directory_url: &str, key_pair: Arc<KeyPair>, contacts: Vec<String>) -> crate::Result<Self> {
let client = Client::builder(TokioExecutor::new()).build(HttpsConnector::new());
let https = HttpsConnectorBuilder::new()
.with_native_roots()
.expect("no native root CA certificates found")
.https_only()
.enable_http1()
.build();
let client = Client::builder(TokioExecutor::new()).build(https);
let directory = get_directory(&client, directory_url).await?;
Ok(Self {
client,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Response {
}
}

let status_code = status_code.unwrap_or_else(|| match &body {
let status_code = status_code.unwrap_or(match &body {
ResBody::None => StatusCode::NOT_FOUND,
ResBody::Error(e) => e.code,
_ => StatusCode::OK,
Expand Down
2 changes: 1 addition & 1 deletion crates/extra/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Handler for Logger {
ctrl.call_next(req, depot, res).await;
let duration = now.elapsed();

let status = res.status_code.unwrap_or_else(|| match &res.body {
let status = res.status_code.unwrap_or(match &res.body {
ResBody::None => StatusCode::NOT_FOUND,
ResBody::Error(e) => e.code,
_ => StatusCode::OK,
Expand Down
4 changes: 2 additions & 2 deletions crates/jwt-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = []
full = ["oidc"]
oidc = ["dep:bytes", "dep:hyper-tls", "dep:hyper-util", "dep:http-body-util"]
oidc = ["dep:bytes", "dep:hyper-rustls", "dep:hyper-util", "dep:http-body-util"]

[dependencies]
base64 = { workspace = true }
bytes = { workspace = true, optional = true }
jsonwebtoken = { workspace = true }
http-body-util = { workspace = true, optional = true }
hyper-tls = { workspace = true, optional = true }
hyper-rustls = { workspace = true, optional = true }
hyper-util = { workspace = true, optional = true, features = ["client-legacy", "http1", "http2", "tokio"] }
salvo_core = { workspace = true, features = ["cookie"] }
serde = { workspace = true, features = ["derive"] }
Expand Down
11 changes: 8 additions & 3 deletions crates/jwt-auth/src/oidc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use base64::Engine;
use bytes::Bytes;
use http_body_util::{BodyExt, Full};
use hyper_tls::HttpsConnector;
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use hyper_util::rt::TokioExecutor;
use jsonwebtoken::jwk::{Jwk, JwkSet};
Expand Down Expand Up @@ -109,8 +109,13 @@ where
let cache = Arc::new(RwLock::new(JwkSetStore::new(jwks, CachePolicy::default(), validation)));
let cache_state = Arc::new(CacheState::new());

let http_client =
http_client.unwrap_or_else(|| Client::builder(TokioExecutor::new()).build(HttpsConnector::new()));
let https = HttpsConnectorBuilder::new()
.with_native_roots()
.expect("no native root CA certificates found")
.https_only()
.enable_http1()
.build();
let http_client = http_client.unwrap_or_else(|| Client::builder(TokioExecutor::new()).build(https));
let decoder = OidcDecoder {
issuer,
http_client,
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub(crate) fn generate(args: DeriveInput) -> Result<TokenStream, Error> {
RenameRule::KebabCase => "KebabCase",
RenameRule::ScreamingKebabCase => "ScreamingKebabCase",
};
let rule = Ident::new(&rename_all, Span::call_site());
let rule = Ident::new(rename_all, Span::call_site());
quote! {
#salvo::extract::RenameRule::#rule
}
Expand Down
5 changes: 2 additions & 3 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ use shared::*;
#[proc_macro_attribute]
pub fn handler(_args: TokenStream, input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as Item);
let stream = match handler::generate(item) {
match handler::generate(item) {
Ok(stream) => stream.into(),
Err(e) => e.to_compile_error().into(),
};
stream
}
}

/// Generate code for extractible type.
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/parameter/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ToTokens for ToParameters {
RenameRule::KebabCase => "KebabCase",
RenameRule::ScreamingKebabCase => "ScreamingKebabCase",
};
let rule = Ident::new(&rename_all, Span::call_site());
let rule = Ident::new(rename_all, Span::call_site());
quote! {
#salvo::extract::RenameRule::#rule
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::borrow::Cow;
use proc_macro2::{Ident, TokenStream};
use proc_macro_error::abort;
use quote::{quote, ToTokens};
use syn::{punctuated::Punctuated, Attribute, Data, Fields, FieldsNamed, FieldsUnnamed, Generics, Token};
use syn::{Attribute, Data, Fields, FieldsNamed, FieldsUnnamed, Generics};

mod enum_schemas;
mod enum_variant;
Expand Down
2 changes: 1 addition & 1 deletion crates/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ tracing = { workspace = true }
tokio = { workspace = true }
fastrand = { workspace = true }
hyper = { workspace = true, features = ["server", "http1", "http2"] }
hyper-rustls = { workspace = true }
hyper-util = { workspace = true, features = ["tokio", "http1", "http2", "client-legacy"] }
hyper-tls = { workspace = true }
percent-encoding = { workspace = true }

[dev-dependencies]
Expand Down
10 changes: 8 additions & 2 deletions crates/proxy/src/clients.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hyper::upgrade::OnUpgrade;
use hyper_tls::HttpsConnector;
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_util::client::legacy::{connect::HttpConnector, Client as HyperUtilClient};
use hyper_util::rt::TokioExecutor;
use salvo_core::http::{ReqBody, ResBody, StatusCode};
Expand All @@ -15,8 +15,14 @@ pub struct HyperClient {
}
impl Default for HyperClient {
fn default() -> Self {
let https = HttpsConnectorBuilder::new()
.with_native_roots()
.expect("no native root CA certificates found")
.https_only()
.enable_http1()
.build();
Self {
inner: HyperUtilClient::builder(TokioExecutor::new()).build(HttpsConnector::new()),
inner: HyperUtilClient::builder(TokioExecutor::new()).build(https),
}
}
}
Expand Down

0 comments on commit 37b619c

Please sign in to comment.