Skip to content

Commit 93ae0d4

Browse files
authored
Patch/box svc improvement (#835)
1 parent 657a87a commit 93ae0d4

File tree

25 files changed

+303
-583
lines changed

25 files changed

+303
-583
lines changed

benches/e2e_http_client_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
use rama::{
1414
Layer, Service,
1515
bytes::Bytes,
16-
error::BoxError,
16+
error::{BoxError, extra::OpaqueError},
1717
extensions::ExtensionsMut,
1818
http::{
1919
HeaderName, HeaderValue, Request, Response, Version,
@@ -269,7 +269,7 @@ fn spawn_http_server(params: TestParameters, body_content: Bytes) -> SocketAddre
269269
fn get_inner_client(
270270
http: HttpVersion,
271271
tls: Tls,
272-
) -> impl Service<Request, Output = Response, Error = BoxError> {
272+
) -> impl Service<Request, Output = Response, Error = OpaqueError> {
273273
let b = EasyHttpWebClient::connector_builder()
274274
.with_default_transport_connector()
275275
.without_tls_proxy_support()

examples/grpc/src/shared/tests/compression/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pin_project_lite::pin_project;
1212
use rama::{
1313
Service,
1414
bytes::{Buf, Bytes},
15-
error::BoxError,
15+
error::{BoxError, extra::OpaqueError},
1616
http::{
1717
self, Body, StreamingBody,
1818
body::{Frame, SizeHint, util::BodyExt as _},
@@ -139,7 +139,7 @@ pub(super) fn measure_request_body_size_layer(
139139
})
140140
}
141141

142-
pub(super) type WebClient = BoxService<http::Request, http::Response, BoxError>;
142+
pub(super) type WebClient = BoxService<http::Request, http::Response, OpaqueError>;
143143

144144
pub(super) fn mock_io_client<F, Server>(make_server: F) -> WebClient
145145
where

examples/grpc/src/shared/tests/examples/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rama::{
22
Service,
3-
error::BoxError,
3+
error::{BoxError, extra::OpaqueError},
44
http::{self, Body, client::EasyHttpWebClient},
55
net::test_utils::client::{MockConnectorService, MockSocket},
66
rt::Executor,
@@ -10,7 +10,7 @@ use rama::{
1010
mod health;
1111
mod helloworld;
1212

13-
pub(super) type WebClient = BoxService<http::Request, http::Response, BoxError>;
13+
pub(super) type WebClient = BoxService<http::Request, http::Response, OpaqueError>;
1414

1515
// TODO: might make sense in future to turn this into a general utility,
1616
// for testing or generic one-time stuff. Be it perhaps with an actual error

examples/grpc/src/shared/tests/integration/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rama::{
22
Service,
3-
error::BoxError,
3+
error::{BoxError, extra::OpaqueError},
44
http::{self, Body, client::EasyHttpWebClient},
55
net::test_utils::client::{MockConnectorService, MockSocket},
66
rt::Executor,
@@ -18,7 +18,7 @@ mod http2_max_header_list_size;
1818
mod max_message_size;
1919
mod timeout;
2020

21-
pub(super) type WebClient = BoxService<http::Request, http::Response, BoxError>;
21+
pub(super) type WebClient = BoxService<http::Request, http::Response, OpaqueError>;
2222

2323
pub(super) fn mock_io_client<F, Server>(make_server: F) -> WebClient
2424
where

examples/tls_sni_proxy_mitm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
8888
use rama::{
8989
Layer, Service,
90-
error::{BoxError, ErrorContext},
90+
error::{BoxError, ErrorContext, extra::OpaqueError},
9191
extensions::{ExtensionsMut, ExtensionsRef},
9292
graceful::Shutdown,
9393
http::{
@@ -317,7 +317,7 @@ struct HttpsMITMService<C> {
317317

318318
impl<C> Service<Request> for HttpsMITMService<C>
319319
where
320-
C: Service<Request, Output = Response, Error = BoxError>,
320+
C: Service<Request, Output = Response, Error = OpaqueError>,
321321
{
322322
type Output = Response;
323323
type Error = BoxError;

rama-cli/src/cmd/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub async fn run(cfg: ResolveCommand) -> Result<(), BoxError> {
2828

2929
let resolver = GlobalDnsResolver::default();
3030
let rt = cfg.record_type.unwrap_or_default();
31-
println!("Resolving {rt:?} for domain: {}...", cfg.domain);
31+
println!("Resolving {rt:?} for domain: {}", cfg.domain);
3232

3333
match rt {
3434
RecordType::A => {

rama-cli/src/cmd/send/http/client/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rama::{
22
Layer, Service,
3-
error::{BoxError, ErrorContext},
3+
error::{BoxError, ErrorContext, ErrorExt, extra::OpaqueError},
44
http::{
55
Request, Response, StreamingBody,
66
client::{
@@ -15,7 +15,7 @@ use rama::{
1515
required_header::AddRequiredRequestHeadersLayer,
1616
},
1717
},
18-
layer::{HijackLayer, MapResultLayer, TimeoutLayer, layer_fn},
18+
layer::{HijackLayer, MapErrLayer, MapResultLayer, TimeoutLayer, layer_fn},
1919
net::{
2020
tls::client::ServerVerifyMode,
2121
user::{Basic, ProxyCredential},
@@ -53,7 +53,7 @@ mod writer;
5353

5454
pub(super) async fn new(
5555
cfg: &SendCommand,
56-
) -> Result<impl Service<Request, Output = Response, Error = BoxError>, BoxError> {
56+
) -> Result<impl Service<Request, Output = Response, Error = OpaqueError>, BoxError> {
5757
let writer = writer::try_new(cfg).await?;
5858

5959
let inner_client = new_inner_client(cfg)?;
@@ -114,6 +114,7 @@ pub(super) async fn new(
114114
},
115115
SetProxyAuthHttpHeaderLayer::default(),
116116
HijackLayer::new(cfg.curl, curl_writer::CurlWriter { writer }),
117+
MapErrLayer::into_box_error(),
117118
layer_fn(move |svc| logger_headers_res::ResponseHeaderLogger {
118119
inner: svc,
119120
show_headers,
@@ -125,7 +126,7 @@ pub(super) async fn new(
125126

126127
fn new_inner_client(
127128
cfg: &SendCommand,
128-
) -> Result<impl Service<Request, Output = Response, Error = BoxError> + Clone, BoxError> {
129+
) -> Result<impl Service<Request, Output = Response, Error = OpaqueError> + Clone, BoxError> {
129130
let mut tls_config = if cfg.emulate {
130131
TlsConnectorDataBuilder::new()
131132
} else {
@@ -209,13 +210,13 @@ pub(super) struct VerboseLogs;
209210

210211
fn map_internal_client_error<E, Body>(
211212
result: Result<Response<Body>, E>,
212-
) -> Result<Response, BoxError>
213+
) -> Result<Response, OpaqueError>
213214
where
214215
E: Into<BoxError>,
215216
Body: StreamingBody<Data = rama::bytes::Bytes, Error: Into<BoxError>> + Send + Sync + 'static,
216217
{
217218
match result {
218219
Ok(response) => Ok(response.map(rama::http::Body::new)),
219-
Err(err) => Err(err.into()),
220+
Err(err) => Err(err.into_opaque_error()),
220221
}
221222
}

rama-cli/src/cmd/send/http/ws/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rama::{
22
Service,
3-
error::{BoxError, ErrorContext},
3+
error::{BoxError, ErrorContext, extra::OpaqueError},
44
extensions::Extensions,
55
http::{
66
Request, Response,
@@ -16,7 +16,7 @@ pub(super) async fn connect<C>(
1616
protocols: Option<NonEmptySmallVec<3, NonEmptyStr>>,
1717
) -> Result<ClientWebSocket, BoxError>
1818
where
19-
C: Service<Request, Output = Response, Error = BoxError>,
19+
C: Service<Request, Output = Response, Error = OpaqueError>,
2020
{
2121
client
2222
.websocket_with_request(req)

rama-cli/src/cmd/send/http/ws/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::time::Duration;
44

55
use rama::{
66
Service,
7-
error::{BoxError, ErrorContext},
7+
error::{BoxError, ErrorContext, extra::OpaqueError},
88
graceful::{self, Shutdown},
99
http::{Request, Response},
1010
utils::{collections::NonEmptySmallVec, str::NonEmptyStr},
@@ -20,7 +20,7 @@ pub(super) async fn run<C>(
2020
protocols: Option<NonEmptySmallVec<3, NonEmptyStr>>,
2121
) -> Result<(), BoxError>
2222
where
23-
C: Service<Request, Output = Response, Error = BoxError>,
23+
C: Service<Request, Output = Response, Error = OpaqueError>,
2424
{
2525
let app = tui::App::new(req, client, protocols)
2626
.await

rama-cli/src/cmd/send/http/ws/tui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rama::{
22
Service,
3-
error::{BoxError, ErrorContext, ErrorExt},
3+
error::{BoxError, ErrorContext, ErrorExt, extra::OpaqueError},
44
futures::{FutureExt, StreamExt},
55
graceful::ShutdownGuard,
66
http::{
@@ -103,7 +103,7 @@ impl App {
103103
protocols: Option<NonEmptySmallVec<3, NonEmptyStr>>,
104104
) -> Result<Self, BoxError>
105105
where
106-
C: Service<Request, Output = Response, Error = BoxError>,
106+
C: Service<Request, Output = Response, Error = OpaqueError>,
107107
{
108108
let title = format!(" rama-ws @ {}", req.uri());
109109

0 commit comments

Comments
 (0)