-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from junkurihara/feat/hyper-1.0
feat: hyper 1.0
- Loading branch information
Showing
17 changed files
with
312 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "submodules/hyper-util"] | ||
path = submodules/hyper-util | ||
url = git@github.com:junkurihara/hyper-util.git | ||
[submodule "submodules/hyper-tls"] | ||
path = submodules/hyper-tls | ||
url = git@github.com:junkurihara/hyper-tls.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::hyper_executor::LocalExecutor; | ||
use http::Request; | ||
use hyper::body::Body; | ||
use hyper_tls::HttpsConnector; | ||
use hyper_util::client::{ | ||
connect::{Connect, HttpConnector}, | ||
legacy::{Client, ResponseFuture}, | ||
}; | ||
|
||
#[derive(Clone)] | ||
/// Http client that is used for forwarding requests to upstream and fetching jwks from auth server. | ||
pub struct HttpClient<C, B> | ||
where | ||
C: Send + Sync + Connect + Clone + 'static, | ||
B: Body + Send + Unpin + 'static, | ||
<B as Body>::Data: Send, | ||
<B as Body>::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>, | ||
{ | ||
pub inner: Client<C, B>, | ||
} | ||
|
||
impl<C, B> HttpClient<C, B> | ||
where | ||
C: Send + Sync + Connect + Clone + 'static, | ||
B: Body + Send + Unpin + 'static, | ||
<B as Body>::Data: Send, | ||
<B as Body>::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>, | ||
{ | ||
/// wrapper request fn | ||
pub fn request(&self, req: Request<B>) -> ResponseFuture { | ||
self.inner.request(req) | ||
} | ||
} | ||
|
||
impl<B> HttpClient<HttpsConnector<HttpConnector>, B> | ||
where | ||
B: Body + Send + Unpin + 'static, | ||
<B as Body>::Data: Send, | ||
<B as Body>::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>, | ||
{ | ||
/// Build inner client with hyper-tls | ||
pub fn new(runtime_handle: tokio::runtime::Handle) -> Self { | ||
// build hyper client with hyper-tls, only https is allowed | ||
let mut connector = HttpsConnector::new(); | ||
connector.https_only(true); | ||
let executor = LocalExecutor::new(runtime_handle.clone()); | ||
let inner = Client::builder(executor).build::<_, B>(connector); | ||
|
||
// build hyper client with rustls and webpki, only https is allowed | ||
// let connector = hyper_rustls::HttpsConnectorBuilder::new() | ||
// .with_webpki_roots() | ||
// .https_only() | ||
// .enable_http1() | ||
// .enable_http2() | ||
// .build(); | ||
// let inner = Client::builder(TokioExecutor::new()).build::<_, B>(connector); | ||
|
||
Self { inner } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use tokio::runtime::Handle; | ||
|
||
#[derive(Clone)] | ||
/// Executor for hyper | ||
pub struct LocalExecutor { | ||
runtime_handle: Handle, | ||
} | ||
|
||
impl LocalExecutor { | ||
pub fn new(runtime_handle: Handle) -> Self { | ||
LocalExecutor { runtime_handle } | ||
} | ||
} | ||
|
||
impl<F> hyper::rt::Executor<F> for LocalExecutor | ||
where | ||
F: std::future::Future + Send + 'static, | ||
F::Output: Send, | ||
{ | ||
fn execute(&self, fut: F) { | ||
self.runtime_handle.spawn(fut); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
mod constants; | ||
mod error; | ||
mod globals; | ||
mod http_client; | ||
mod hyper_executor; | ||
mod log; | ||
mod relay; | ||
mod validator; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.