Skip to content

Commit

Permalink
Fix error when returning response when route is not known in DevnetPr…
Browse files Browse the repository at this point in the history
…oxyLayer
  • Loading branch information
fabrobles92 committed Jan 4, 2025
1 parent 3d73532 commit 17a53b5
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions crates/katana/rpc/rpc/src/proxy_get_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use futures::future;
use hyper::header::{ACCEPT, CONTENT_TYPE};
use hyper::http::HeaderValue;
use hyper::{Body, Method, Request, Response, Uri};
Expand Down Expand Up @@ -94,32 +93,39 @@ where
_ => (JsonRawValue::from_string("{}".to_string()).unwrap(), "".to_string()),
};

if method.is_empty() {
return Box::pin(future::ok(http::response::ok_response("Unknown route".to_string())));
}

// RPC methods are accessed with `POST`.
*req.method_mut() = Method::POST;
// Precautionary remove the URI.
*req.uri_mut() = Uri::from_static("/");

// Requests must have the following headers:
req.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
req.headers_mut().insert(ACCEPT, HeaderValue::from_static("application/json"));

// Adjust the body to reflect the method call.
let body = Body::from(
serde_json::to_string(&RequestSer::borrowed(&Id::Number(0), &method, Some(&params)))
if !method.is_empty() {
// RPC methods are accessed with `POST`.
*req.method_mut() = Method::POST;
// Precautionary remove the URI.
*req.uri_mut() = Uri::from_static("/");

// Requests must have the following headers:
req.headers_mut().insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
req.headers_mut().insert(ACCEPT, HeaderValue::from_static("application/json"));

// Adjust the body to reflect the method call.
let body = Body::from(
serde_json::to_string(&RequestSer::borrowed(
&Id::Number(0),
&method,
Some(&params),
))
.expect("Valid request; qed"),
);
req = req.map(|_| body);
);
req = req.map(|_| body);

Check warning on line 115 in crates/katana/rpc/rpc/src/proxy_get_request.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/rpc/rpc/src/proxy_get_request.rs#L97-L115

Added lines #L97 - L115 were not covered by tests
}

// Call the inner service and get a future that resolves to the response.
let fut = self.inner.call(req);

// Adjust the response if needed.
let res_fut = async move {
let res = fut.await.map_err(|err| err.into())?;

if method.is_empty() {
return Ok(res);
}

let body = res.into_body();
let bytes = hyper::body::to_bytes(body).await?;

Check warning on line 130 in crates/katana/rpc/rpc/src/proxy_get_request.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/rpc/rpc/src/proxy_get_request.rs#L127-L130

Added lines #L127 - L130 were not covered by tests

Expand Down

0 comments on commit 17a53b5

Please sign in to comment.