Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Dec 12, 2023
1 parent 21f85ad commit eeb672f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 27 deletions.
8 changes: 2 additions & 6 deletions crates/core/src/conn/acme/client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use std::{
io::{Error as IoError, ErrorKind, Result as IoResult},
sync::Arc,
time::Duration,
};
use std::sync::Arc;

use base64::engine::{general_purpose::URL_SAFE_NO_PAD, Engine};
use bytes::Bytes;
use http_body_util::{BodyExt, Full};
use hyper::{body::Incoming as HyperBody, Uri};
use hyper::Uri;
use hyper_tls::HttpsConnector;
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use hyper_util::rt::TokioExecutor;
Expand Down
7 changes: 2 additions & 5 deletions crates/core/src/conn/acme/issuer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::io::{Error as IoError, ErrorKind, Result as IoResult};
use std::io::Result as IoResult;
use std::sync::Arc;
use std::time::Duration;

use rcgen::{Certificate, CertificateParams, CustomExtension, DistinguishedName, PKCS_ECDSA_P256_SHA256};
use rustls_pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
use tokio_rustls::rustls::{
crypto::ring::sign::{any_ecdsa_type, any_eddsa_type},
sign::CertifiedKey,
};
use tokio_rustls::rustls::{crypto::ring::sign::any_ecdsa_type, sign::CertifiedKey};

use super::cache::AcmeCache;
use super::client::AcmeClient;
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/acme/jose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::io::{Error as IoError, ErrorKind, Result as IoResult};
use super::client::HyperClient;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use base64::Engine;
use bytes::Bytes;
use http_body_util::{BodyExt, Full};
use hyper::{body::Incoming as HyperBody, Method};
use ring::digest::{digest, Digest, SHA256};
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/conn/acme/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::path::PathBuf;
use std::sync::{Arc, Weak};
use std::time::Duration;

use rustls_pki_types::{PrivateKeyDer, CertificateDer};
use rustls_pki_types::{CertificateDer, PrivateKeyDer};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls::rustls::crypto::ring::sign::{any_ecdsa_type, any_supported_type};
use tokio_rustls::rustls::crypto::ring::sign::any_ecdsa_type;
use tokio_rustls::rustls::server::ServerConfig;
use tokio_rustls::rustls::sign::{CertifiedKey, SigningKey};
use tokio_rustls::rustls::sign::CertifiedKey;
use tokio_rustls::server::TlsStream;
use tokio_rustls::TlsAcceptor;

Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/conn/rustls/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::sync::Arc;

use futures_util::stream::{once, Once, Stream};
use rustls_pki_types::{CertificateDer, PrivateKeyDer};
use tokio_rustls::rustls::crypto::ring::sign::{any_ecdsa_type, any_supported_type};
use tokio_rustls::rustls::server::{ClientHello, NoClientAuth, ResolvesServerCert, WebPkiClientVerifier};
use tokio_rustls::rustls::sign::{self, CertifiedKey};
use tokio_rustls::rustls::crypto::ring::sign::any_supported_type;
use tokio_rustls::rustls::server::{ClientHello, ResolvesServerCert, WebPkiClientVerifier};
use tokio_rustls::rustls::sign::CertifiedKey;

pub use tokio_rustls::rustls::server::ServerConfig;

Expand Down
1 change: 1 addition & 0 deletions crates/otel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ opentelemetry-http = { workspace = true }
opentelemetry-semantic-conventions = { workspace = true }
opentelemetry = { workspace = true, features = ["metrics"] }
salvo_core = { workspace = true, default-features = false }
headers03 = {version = "0.3", package = "headers"}

[dev-dependencies]
salvo_core = { workspace = true, features = ["test"] }
Expand Down
11 changes: 10 additions & 1 deletion crates/otel/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use opentelemetry_http::HeaderExtractor;
use opentelemetry_semantic_conventions::{resource, trace};
use salvo_core::http::headers::{self, HeaderMapExt};
use salvo_core::prelude::*;
use headers03::{HeaderMap, HeaderName, HeaderValue};

/// Middleware for tracing with OpenTelemetry.
pub struct Tracing<T> {
Expand All @@ -26,8 +27,16 @@ where
async fn handle(&self, req: &mut Request, depot: &mut Depot, res: &mut Response, ctrl: &mut FlowCtrl) {
let remote_addr = req.remote_addr().to_string();

//TODO: Will remove after opentelemetry_http updated
let mut headers = HeaderMap::with_capacity(req.headers().len());
headers.extend(req.headers().into_iter().map(|(name, value)| {
let name = HeaderName::from_bytes(name.as_ref()).unwrap();
let value = HeaderValue::from_bytes(value.as_ref()).unwrap();
(name, value)
}));

let parent_cx =
global::get_text_map_propagator(|propagator| propagator.extract(&HeaderExtractor(req.headers())));
global::get_text_map_propagator(|propagator| propagator.extract(&HeaderExtractor(&headers)));

let mut attributes = Vec::new();
attributes.push(resource::TELEMETRY_SDK_NAME.string(env!("CARGO_CRATE_NAME")));
Expand Down
11 changes: 4 additions & 7 deletions crates/proxy/src/clients.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use futures_util::TryStreamExt;
use hyper::upgrade::OnUpgrade;
use hyper_tls::HttpsConnector;
use hyper_util::client::legacy::{connect::HttpConnector, Client as HyperUtilClient};
use hyper_util::rt::TokioExecutor;
use salvo_core::http::header::{HeaderMap, HeaderName, HeaderValue, CONNECTION, HOST, UPGRADE};
use salvo_core::http::uri::{Scheme, Uri};
use salvo_core::http::{response, ReqBody, ResBody, StatusCode};
use salvo_core::http::{ReqBody, ResBody, StatusCode};
use salvo_core::rt::tokio::TokioIo;
use salvo_core::{async_trait, BoxedError, Depot, Error, FlowCtrl, Handler, Request, Response};
use salvo_core::{async_trait, Error};
use tokio::io::copy_bidirectional;

use super::{HyperRequest, HyperResponse};

/// A [`Client`] implementation based on [`hyper_util::client::legacy::Client`].
pub struct HyperClient {
inner: HyperUtilClient<HttpsConnector<HttpConnector>, ReqBody>,
}
Expand All @@ -23,6 +21,7 @@ impl Default for HyperClient {
}
}
impl HyperClient {
/// Create a new `HyperClient` with the given `HyperClient`.
pub fn new(inner: HyperUtilClient<HttpsConnector<HttpConnector>, ReqBody>) -> Self {
Self { inner }
}
Expand All @@ -45,12 +44,10 @@ impl super::Client for HyperClient {
let response_upgrade_type = crate::get_upgrade_type(response.headers());
if request_upgrade_type.as_deref() == response_upgrade_type {
let response_upgraded = hyper::upgrade::on(&mut response).await.unwrap();
println!("--------------------1");
if let Some(request_upgraded) = request_upgraded {
tokio::spawn(async move {
match request_upgraded.await {
Ok(request_upgraded) => {
println!("--------------------2");
let mut request_upgraded = TokioIo::new(request_upgraded);
let mut response_upgraded = TokioIo::new(response_upgraded);
if let Err(e) = copy_bidirectional(&mut response_upgraded, &mut request_upgraded).await
Expand Down
1 change: 0 additions & 1 deletion crates/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use std::convert::{Infallible, TryFrom};

use futures_util::TryStreamExt;
use hyper::upgrade::OnUpgrade;
use percent_encoding::{utf8_percent_encode, CONTROLS};
use salvo_core::http::header::{HeaderMap, HeaderName, HeaderValue, CONNECTION, HOST, UPGRADE};
Expand Down

0 comments on commit eeb672f

Please sign in to comment.