Skip to content

Commit

Permalink
fix(deps): enable feature flag for hyper deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
amitksingh1490 committed Sep 29, 2024
1 parent 1dbf9eb commit bf054d7
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ genai = { git = "https://github.com/laststylebender14/rust-genai.git", rev = "63

rustls-pemfile = { version = "1.0.4" }
schemars = { version = "0.8.17", features = ["derive"] }
hyper = { version = "0.14.28", features = ["server"], default-features = false }
hyper = { version = "0.14.28", features = ["server", "backports", "deprecated"], default-features = false }
tokio = { workspace = true }
anyhow = { workspace = true }
reqwest = { workspace = true }
Expand Down
16 changes: 13 additions & 3 deletions src/core/async_graphql_hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl GraphQLResponse {
mod tests {
use async_graphql::{Name, Response, ServerError, Value};
use http::StatusCode;
use hyper::body::HttpBody;
use indexmap::IndexMap;
use serde_json::json;

Expand All @@ -289,9 +290,12 @@ mod tests {
assert_eq!(rest_response.status(), StatusCode::OK);
assert_eq!(rest_response.headers()["content-type"], "application/json");
assert_eq!(
hyper::body::to_bytes(rest_response.into_body())
rest_response
.into_body()
.collect()
.await
.unwrap()
.to_bytes()
.to_vec(),
json!({ "name": name }).to_string().as_bytes().to_vec()
);
Expand All @@ -316,9 +320,12 @@ mod tests {
assert_eq!(rest_response.status(), StatusCode::OK);
assert_eq!(rest_response.headers()["content-type"], "application/json");
assert_eq!(
hyper::body::to_bytes(rest_response.into_body())
rest_response
.into_body()
.collect()
.await
.unwrap()
.to_bytes()
.to_vec(),
json!([
{ "name": names[0] },
Expand All @@ -345,9 +352,12 @@ mod tests {
assert_eq!(rest_response.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(rest_response.headers()["content-type"], "application/json");
assert_eq!(
hyper::body::to_bytes(rest_response.into_body())
rest_response
.into_body()
.collect()
.await
.unwrap()
.to_bytes()
.to_vec(),
json!({
"data": null,
Expand Down
9 changes: 6 additions & 3 deletions src/core/http/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;
use async_graphql::ServerError;
use http::header::{self, HeaderMap, HeaderValue, CONTENT_TYPE};
use http::{Method, Request, Response, StatusCode};
use hyper::body::HttpBody;
use hyper::Body;
use opentelemetry::trace::SpanKind;
use opentelemetry_semantic_conventions::trace::{HTTP_REQUEST_METHOD, HTTP_ROUTE};
Expand Down Expand Up @@ -105,7 +106,7 @@ pub async fn graphql_request<T: DeserializeOwned + GraphQLRequestLike>(
req_counter.set_http_route("/graphql");
let req_ctx = Arc::new(create_request_context(&req, app_ctx));
let (req, body) = req.into_parts();
let bytes = hyper::body::to_bytes(body).await?;
let bytes = body.collect().await?.to_bytes();
let graphql_request = serde_json::from_slice::<T>(&bytes);
match graphql_request {
Ok(mut request) => {
Expand Down Expand Up @@ -385,6 +386,8 @@ pub async fn handle_request<T: DeserializeOwned + GraphQLRequestLike>(

#[cfg(test)]
mod test {
use hyper::body::HttpBody;

use super::*;
use crate::core::async_graphql_hyper::GraphQLRequest;
use crate::core::blueprint::Blueprint;
Expand Down Expand Up @@ -413,7 +416,7 @@ mod test {
let resp = handle_request::<GraphQLRequest>(req, app_ctx).await?;

assert_eq!(resp.status(), StatusCode::OK);
let body = hyper::body::to_bytes(resp.into_body()).await?;
let body = resp.into_body().collect().await?.to_bytes();
assert_eq!(body, r#"{"message": "ready"}"#);

Ok(())
Expand Down Expand Up @@ -441,7 +444,7 @@ mod test {
let resp = handle_request::<GraphQLRequest>(req, app_ctx).await?;

assert_eq!(resp.status(), StatusCode::OK);
let body = hyper::body::to_bytes(resp.into_body()).await?;
let body = resp.into_body().collect().await?.to_bytes();
let body_str = String::from_utf8(body.to_vec())?;
assert!(body_str.contains("queryType"));
assert!(body_str.contains("name"));
Expand Down
4 changes: 2 additions & 2 deletions src/core/http/response.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use async_graphql_value::{ConstValue, Name};
use derive_setters::Setters;
use hyper::body::Bytes;
use hyper::body::{Bytes, HttpBody};
use hyper::Body;
use indexmap::IndexMap;
use prost::Message;
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Response<Bytes> {
pub async fn from_hyper(resp: http::Response<hyper::Body>) -> Result<Self> {
let status = resp.status();
let headers = resp.headers().to_owned();
let body = hyper::body::to_bytes(resp.into_body()).await?;
let body = resp.into_body().collect().await?.to_bytes();
Ok(Response { status, headers, body })
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/rest/partial_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_graphql::parser::types::ExecutableDocument;
use async_graphql::{Name, Variables};
use async_graphql_value::ConstValue;
use hyper::body::HttpBody;

use super::path::Path;
use super::{Request, Result};
Expand All @@ -19,7 +20,7 @@ impl<'a> PartialRequest<'a> {
pub async fn into_request(self, request: Request) -> Result<GraphQLRequest> {
let mut variables = self.variables;
if let Some(key) = self.body {
let bytes = hyper::body::to_bytes(request.into_body()).await?;
let bytes = request.into_body().collect().await?.to_bytes();

Check warning on line 23 in src/core/rest/partial_request.rs

View check run for this annotation

Codecov / codecov/patch

src/core/rest/partial_request.rs#L23

Added line #L23 was not covered by tests
let body: ConstValue = serde_json::from_slice(&bytes)?;
variables.insert(Name::new(key), body);
}
Expand Down
4 changes: 2 additions & 2 deletions tailcall-aws-lambda/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use anyhow::Result;
use hyper::body::Bytes;
use hyper::body::{Bytes, HttpBody};
use lambda_http::RequestExt;
use reqwest::Client;
use tailcall::core::http::Response;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub async fn to_response(
}

build.body(lambda_http::Body::Binary(Vec::from(
hyper::body::to_bytes(res.into_body()).await.unwrap(),
res.into_body().collect().await.unwrap().to_bytes(),
)))
}

Expand Down
4 changes: 2 additions & 2 deletions tailcall-cloudflare/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use async_std::task::spawn_local;
use hyper::body::Bytes;
use hyper::body::{Bytes, HttpBody};
use reqwest::Client;
use tailcall::core::http::Response;
use tailcall::core::HttpIO;
Expand Down Expand Up @@ -53,7 +53,7 @@ impl HttpIO for CloudflareHttp {
pub async fn to_response(response: http::Response<hyper::Body>) -> Result<worker::Response> {
let status = response.status().as_u16();
let headers = response.headers().clone();
let bytes = hyper::body::to_bytes(response).await?;
let bytes = response.collect().await?.to_bytes();

Check warning on line 56 in tailcall-cloudflare/src/http.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-cloudflare/src/http.rs#L56

Added line #L56 was not covered by tests
let body = worker::ResponseBody::Body(bytes.to_vec());
let mut w_response = worker::Response::from_body(body).map_err(to_anyhow)?;
w_response = w_response.with_status(status);
Expand Down
3 changes: 2 additions & 1 deletion tailcall-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display;
use std::panic;
use std::sync::Arc;

use hyper::body::HttpBody;
use serde_json::json;
use tailcall::core::app_context::AppContext;
use tailcall::core::async_graphql_hyper::GraphQLRequest;
Expand Down Expand Up @@ -37,7 +38,7 @@ impl TailcallExecutor {
let resp = handle_request::<GraphQLRequest>(req, self.app_context.clone()).await?;
tracing::debug!("{:#?}", resp);

let body_bytes = hyper::body::to_bytes(resp.into_body()).await?;
let body_bytes = resp.into_body().collect().await?.to_bytes();

Check warning on line 41 in tailcall-wasm/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-wasm/src/lib.rs#L41

Added line #L41 was not covered by tests
let body_str = String::from_utf8(body_bytes.to_vec())?;
Ok(body_str)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/core/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::Context;
use colored::Colorize;
use futures_util::future::join_all;
use http::Request;
use hyper::body::HttpBody;
use hyper::Body;
use serde::{Deserialize, Serialize};
use tailcall::core::app_context::AppContext;
Expand Down Expand Up @@ -192,7 +193,7 @@ async fn run_query_tests_on_spec(
headers,
body: Some(APIBody::Value(
serde_json::from_slice(
&hyper::body::to_bytes(response.into_body()).await.unwrap(),
&response.into_body().collect().await.unwrap().to_bytes(),
)
.unwrap_or_default(),
)),
Expand Down

1 comment on commit bf054d7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 11.49ms 4.52ms 154.59ms 89.51%
Req/Sec 2.21k 254.44 2.74k 83.67%

264380 requests in 30.05s, 1.33GB read

Requests/sec: 8798.38

Transfer/sec: 45.16MB

Please sign in to comment.