Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Arya <[email protected]>
  • Loading branch information
oxarbitrage and arya2 authored Dec 20, 2024
1 parent d338313 commit 06d8871
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions zebra-rpc/src/server/http_request_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<S> HttpRequestMiddleware<S> {
// - use a regular expression
//
// We could also just handle the exact lightwalletd format,
// by replacing `{"jsonrpc":"1.0",` with `{`.
// by replacing `{"jsonrpc":"1.0",` with `{"jsonrpc":"2.0`.
data.replace("\"jsonrpc\":\"1.0\",", "\"jsonrpc\":\"2.0\",")
.replace("\"jsonrpc\": \"1.0\",", "\"jsonrpc\": \"2.0\",")
.replace(",\"jsonrpc\":\"1.0\"", ",\"jsonrpc\":\"2.0\"")
Expand Down Expand Up @@ -202,26 +202,26 @@ where
// Fix the request headers.
Self::insert_or_replace_content_type_header(request.headers_mut());

// Fix the request body
let request = request.map(|body| {
let new_body = tokio::task::block_in_place(|| {
let bytes = tokio::runtime::Handle::current().block_on(async {
body.collect()
.await
.expect("Failed to collect body data")
.to_bytes()
});
let data = String::from_utf8_lossy(bytes.as_ref()).to_string();
let mut service = self.service.clone();

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Build and Deploy Zebra Internal Docs

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Check Cargo.lock is up to date

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

no method named `clone` found for type parameter `S` in the current scope

error[E0599]: no method named `clone` found for type parameter `S` in the current scope --> zebra-rpc/src/server/http_request_compatibility.rs:205:40 | 176 | impl<S> Service<HttpRequest<HttpBody>> for HttpRequestMiddleware<S> | - method `clone` not found for this type parameter ... 205 | let mut service = self.service.clone(); | ^^^^^ method not found in `S` | = help: items from traits can only be used if the type parameter is bounded by the trait help: the following trait defines an item `clone`, perhaps you need to restrict type parameter `S` with it: | 178 | S: Service<HttpRequest, Response = HttpResponse> + std::clone::Clone, | +++++++++++++++++++

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

no method named `clone` found for type parameter `S` in the current scope

error[E0599]: no method named `clone` found for type parameter `S` in the current scope --> zebra-rpc/src/server/http_request_compatibility.rs:205:40 | 176 | impl<S> Service<HttpRequest<HttpBody>> for HttpRequestMiddleware<S> | - method `clone` not found for this type parameter ... 205 | let mut service = self.service.clone(); | ^^^^^ method not found in `S` | = help: items from traits can only be used if the type parameter is bounded by the trait help: the following trait defines an item `clone`, perhaps you need to restrict type parameter `S` with it: | 178 | S: Service<HttpRequest, Response = HttpResponse> + std::clone::Clone, | +++++++++++++++++++

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

no method named `clone` found for type parameter `S` in the current scope

error[E0599]: no method named `clone` found for type parameter `S` in the current scope --> zebra-rpc/src/server/http_request_compatibility.rs:205:40 | 176 | impl<S> Service<HttpRequest<HttpBody>> for HttpRequestMiddleware<S> | - method `clone` not found for this type parameter ... 205 | let mut service = self.service.clone(); | ^^^^^ method not found in `S` | = help: items from traits can only be used if the type parameter is bounded by the trait help: the following trait defines an item `clone`, perhaps you need to restrict type parameter `S` with it: | 178 | S: Service<HttpRequest, Response = HttpResponse> + std::clone::Clone, | +++++++++++++++++++

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Test stable on ubuntu-latest

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Test stable on macos-latest

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Install zebrad from lockfile without cache on ubuntu-latest

no method named `clone` found for type parameter `S` in the current scope

Check failure on line 205 in zebra-rpc/src/server/http_request_compatibility.rs

View workflow job for this annotation

GitHub Actions / Build zebrad crate

no method named `clone` found for type parameter `S` in the current scope
let (parts, body) = request.into_parts();

// Fix JSON-RPC 1.0 requests.
let new_data = Self::remove_json_1_fields(data);
async move {
let bytes = body
.collect()
.await
.expect("Failed to collect body data")
.to_bytes();

HttpBody::from(Bytes::from(new_data).as_ref().to_vec())
});
let data = String::from_utf8_lossy(bytes.as_ref()).to_string();

new_body
});
// Fix JSON-RPC 1.0 requests.
let data = Self::remove_json_1_fields(data);
let body = HttpBody::from(Bytes::from(data).as_ref().to_vec());

Box::pin(self.service.call(request).map_err(Into::into))
let request = HttpRequest::from_parts(parts, body);

service.call(request).await.map_err(Into::into)
}
.boxed()
}
}

0 comments on commit 06d8871

Please sign in to comment.