From 8ffb725fcb6714f44daecc31e6e6273a39923c88 Mon Sep 17 00:00:00 2001 From: hatoo Date: Fri, 8 Nov 2024 16:48:17 +0900 Subject: [PATCH 1/3] wip --- src/lib.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 26c57e4..0896722 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use hyper::{ }; use hyper_util::rt::{TokioExecutor, TokioIo}; use moka::sync::Cache; -use std::{borrow::Borrow, future::Future, sync::Arc}; +use std::{borrow::Borrow, error::Error as StdError, future::Future, sync::Arc}; use tls::{generate_cert, CertifiedKeyDer}; use tokio::net::{TcpListener, TcpStream, ToSocketAddrs}; @@ -52,17 +52,18 @@ impl MitmProxy { impl + Send + Sync + 'static> MitmProxy { /// Bind to a socket address and return a future that runs the proxy server. /// URL for requests that passed to service are full URL including scheme. - pub async fn bind( + pub async fn bind( self, addr: A, service: S, ) -> Result, std::io::Error> where - S: HttpService + Send + Clone + 'static, - B::Data: Send + 'static, - B: Body + Send + Sync + 'static, - B::Error: Into>, - E: std::error::Error + Send + Sync + 'static, + S: HttpService + Clone + Send + 'static, + S::Error: Into>, + ::Data: Send, + S::ResBody: Send + Sync + 'static, + ::Error: Into>, + S::Future: Send, { let listener = TcpListener::bind(addr).await?; @@ -100,16 +101,21 @@ impl + Send + Sync + 'static> MitmProxy { /// See `examples/https.rs` for usage. /// If you want to serve simple HTTP proxy server, you can use `bind` method instead. /// `bind` will call this method internally. - pub fn wrap_service( + pub fn wrap_service( proxy: Arc, service: S, - ) -> impl HttpService, Future: Send> + ) -> impl HttpService< + Incoming, + ResBody = BoxBody<::Data, ::Error>, + Future: Send, + > where - S: HttpService + Send + Clone + 'static, - B::Data: Send + 'static, - B: Body + Send + Sync + 'static, - B::Error: Into>, - E: std::error::Error + Send + Sync + 'static, + S: HttpService + Clone + Send + 'static, + S::Error: Into>, + ::Data: Send, + S::ResBody: Send + Sync + 'static, + ::Error: Into>, + S::Future: Send, { service_fn(move |req| { let proxy = proxy.clone(); From 8c9da6bcf4f0bb5634571f5350f233715c0dccfc Mon Sep 17 00:00:00 2001 From: hatoo Date: Fri, 8 Nov 2024 17:03:04 +0900 Subject: [PATCH 2/3] tweak --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0896722..ea98cf3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,10 @@ impl MitmProxy { // pub type Handler = Fn(Request) -> Result, E>; -impl + Send + Sync + 'static> MitmProxy { +impl MitmProxy +where + C: Borrow + Send + Sync + 'static, +{ /// Bind to a socket address and return a future that runs the proxy server. /// URL for requests that passed to service are full URL including scheme. pub async fn bind( From 9a45ba16bfa47d0a41957c2730f8b47d15b5cdfe Mon Sep 17 00:00:00 2001 From: hatoo Date: Fri, 8 Nov 2024 17:09:33 +0900 Subject: [PATCH 3/3] ok --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ea98cf3..20bbf40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,8 +63,8 @@ where where S: HttpService + Clone + Send + 'static, S::Error: Into>, - ::Data: Send, S::ResBody: Send + Sync + 'static, + ::Data: Send, ::Error: Into>, S::Future: Send, { @@ -115,8 +115,8 @@ where where S: HttpService + Clone + Send + 'static, S::Error: Into>, - ::Data: Send, S::ResBody: Send + Sync + 'static, + ::Data: Send, ::Error: Into>, S::Future: Send, {