diff --git a/Cargo.toml b/Cargo.toml index 77941f77499..f7431b7d954 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/core/async_graphql_hyper.rs b/src/core/async_graphql_hyper.rs index d12f9ecaae4..54f02c97b6b 100644 --- a/src/core/async_graphql_hyper.rs +++ b/src/core/async_graphql_hyper.rs @@ -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; @@ -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() ); @@ -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] }, @@ -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, diff --git a/src/core/http/request_handler.rs b/src/core/http/request_handler.rs index e964ca9ef85..962640be9b7 100644 --- a/src/core/http/request_handler.rs +++ b/src/core/http/request_handler.rs @@ -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}; @@ -105,7 +106,7 @@ pub async fn graphql_request( 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::(&bytes); match graphql_request { Ok(mut request) => { @@ -385,6 +386,8 @@ pub async fn handle_request( #[cfg(test)] mod test { + use hyper::body::HttpBody; + use super::*; use crate::core::async_graphql_hyper::GraphQLRequest; use crate::core::blueprint::Blueprint; @@ -413,7 +416,7 @@ mod test { let resp = handle_request::(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(()) @@ -441,7 +444,7 @@ mod test { let resp = handle_request::(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")); diff --git a/src/core/http/response.rs b/src/core/http/response.rs index bfbbb22bc03..522456a376c 100644 --- a/src/core/http/response.rs +++ b/src/core/http/response.rs @@ -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; @@ -59,7 +59,7 @@ impl Response { pub async fn from_hyper(resp: http::Response) -> Result { 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 }) } diff --git a/src/core/rest/partial_request.rs b/src/core/rest/partial_request.rs index dab44c810c0..7e7d428394b 100644 --- a/src/core/rest/partial_request.rs +++ b/src/core/rest/partial_request.rs @@ -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}; @@ -19,7 +20,7 @@ impl<'a> PartialRequest<'a> { pub async fn into_request(self, request: Request) -> Result { 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(); let body: ConstValue = serde_json::from_slice(&bytes)?; variables.insert(Name::new(key), body); } diff --git a/tailcall-aws-lambda/src/http.rs b/tailcall-aws-lambda/src/http.rs index 8541a2f898f..dc8a2af14a5 100644 --- a/tailcall-aws-lambda/src/http.rs +++ b/tailcall-aws-lambda/src/http.rs @@ -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; @@ -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(), ))) } diff --git a/tailcall-cloudflare/src/http.rs b/tailcall-cloudflare/src/http.rs index 27aa6da46e7..e3ffadb412a 100644 --- a/tailcall-cloudflare/src/http.rs +++ b/tailcall-cloudflare/src/http.rs @@ -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; @@ -53,7 +53,7 @@ impl HttpIO for CloudflareHttp { pub async fn to_response(response: http::Response) -> Result { 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(); 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); diff --git a/tailcall-wasm/src/lib.rs b/tailcall-wasm/src/lib.rs index 4ec3e5a3dd2..b03faf97499 100644 --- a/tailcall-wasm/src/lib.rs +++ b/tailcall-wasm/src/lib.rs @@ -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; @@ -37,7 +38,7 @@ impl TailcallExecutor { let resp = handle_request::(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(); let body_str = String::from_utf8(body_bytes.to_vec())?; Ok(body_str) } diff --git a/tests/core/spec.rs b/tests/core/spec.rs index be287d044c0..1c7935b734a 100644 --- a/tests/core/spec.rs +++ b/tests/core/spec.rs @@ -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; @@ -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(), )),