From f20bd2f547769685d7e23142abda91bf8a7fa0c2 Mon Sep 17 00:00:00 2001 From: amit Date: Sun, 29 Sep 2024 13:53:48 +0530 Subject: [PATCH] chore(deps): use http crate for consistency --- Cargo.lock | 7 +++- Cargo.toml | 4 ++- benches/from_json_bench.rs | 2 +- benches/handle_request_bench.rs | 2 +- benches/http_execute_bench.rs | 2 +- ...impl_path_string_for_evaluation_context.rs | 2 +- benches/request_template_bench.rs | 2 +- src/cli/generator/generator.rs | 2 +- src/cli/javascript/codec.rs | 6 ++-- src/cli/javascript/mod.rs | 2 +- src/core/async_graphql_hyper.rs | 8 ++--- src/core/auth/basic.rs | 2 +- src/core/blueprint/cors.rs | 10 +++--- src/core/blueprint/server.rs | 2 +- src/core/blueprint/telemetry.rs | 2 +- src/core/blueprint/upstream.rs | 2 +- src/core/config/cors.rs | 2 +- src/core/config/reader_context.rs | 2 +- src/core/endpoint.rs | 2 +- src/core/graphql/request_template.rs | 4 +-- src/core/grpc/data_loader_request.rs | 2 +- src/core/grpc/request.rs | 7 ++-- src/core/grpc/request_template.rs | 7 ++-- src/core/has_headers.rs | 2 +- src/core/helpers/headers.rs | 4 +-- src/core/http/cache.rs | 4 +-- src/core/http/data_loader_request.rs | 2 +- src/core/http/method.rs | 20 +++++------ src/core/http/mod.rs | 2 +- src/core/http/request_context.rs | 2 +- src/core/http/request_handler.rs | 21 ++++++----- src/core/http/request_template.rs | 8 ++--- src/core/http/response.rs | 6 ++-- src/core/http/showcase.rs | 5 +-- src/core/http/telemetry.rs | 3 +- src/core/ir/eval_context.rs | 2 +- src/core/path.rs | 2 +- src/core/proto_reader/fetch.rs | 2 +- src/core/rest/endpoint.rs | 5 +-- src/core/rest/error.rs | 4 +-- src/core/rest/mod.rs | 2 +- src/core/valid/error.rs | 4 +-- src/core/worker/error.rs | 6 ++-- tailcall-aws-lambda/Cargo.toml | 1 + tailcall-aws-lambda/src/http.rs | 35 ++++++++++--------- tailcall-cloudflare/Cargo.toml | 1 + tailcall-cloudflare/src/handle.rs | 3 +- tailcall-cloudflare/src/http.rs | 30 ++++++++-------- tailcall-tracker/Cargo.toml | 2 +- tailcall-tracker/src/collect/ga.rs | 2 +- tailcall-tracker/src/collect/posthog.rs | 2 +- tailcall-upstream-grpc/Cargo.toml | 1 + tailcall-upstream-grpc/src/error.rs | 2 +- tailcall-upstream-grpc/src/main.rs | 2 +- tailcall-wasm/Cargo.toml | 3 +- tailcall-wasm/src/lib.rs | 6 ++-- tests/core/http.rs | 2 +- tests/core/spec.rs | 5 +-- 58 files changed, 152 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcebd800d9f..42307ce8256 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5386,6 +5386,7 @@ dependencies = [ "getrandom", "headers", "htpasswd-verify", + "http 0.2.12", "http-cache-reqwest", "http-cache-semantics", "httpmock", @@ -5478,6 +5479,7 @@ dependencies = [ "async-graphql-value", "async-trait", "dotenvy", + "http 0.2.12", "hyper 0.14.30", "lambda_http", "lambda_runtime", @@ -5497,6 +5499,7 @@ dependencies = [ "async-std", "async-trait", "console_error_panic_hook", + "http 0.2.12", "hyper 0.14.30", "lazy_static", "protox 0.7.1", @@ -5569,7 +5572,7 @@ dependencies = [ "chrono", "convert_case 0.6.0", "derive_more 0.99.18", - "headers", + "http 0.2.12", "lazy_static", "machineid-rs", "posthog-rs", @@ -5616,6 +5619,7 @@ version = "0.1.0" dependencies = [ "derive_more 0.99.18", "headers", + "http 0.2.12", "http-body-util", "hyper 0.14.30", "hyper-util", @@ -5655,6 +5659,7 @@ dependencies = [ "async-trait", "console_error_panic_hook", "dashmap", + "http 0.2.12", "hyper 0.14.30", "reqwest 0.11.27", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 4a19269a135..77941f77499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ async-graphql = { version = "7.0.9" } futures-util = { version = "0.3.30" } indexmap = "2.2.6" headers = "0.3.9" # previous version until hyper is updated to 1+ +http = "0.2.12" # previous version until hyper is updated to 1+ insta = { version = "1.38.0", features = ["json"] } tokio = { version = "1.37.0", features = ["rt", "time"] } reqwest = { version = "0.11", features = [ @@ -139,7 +140,8 @@ opentelemetry-prometheus = "0.16.0" phonenumber = "0.3.4" chrono = "0.4.38" async-graphql-extension-apollo-tracing = { version = "3.2.15" } -headers = { workspace = true } # previous version until hyper is updated to 1+ +headers = { workspace = true } +http = { workspace = true } mime = "0.3.17" htpasswd-verify = { version = "0.3.0", git = "https://github.com/twistedfall/htpasswd-verify", rev = "ff14703083cbd639f7d05622b398926f3e718d61" } # fork version that is wasm compatible jsonwebtoken = "9.3.0" diff --git a/benches/from_json_bench.rs b/benches/from_json_bench.rs index e953d9459dc..43459143f90 100644 --- a/benches/from_json_bench.rs +++ b/benches/from_json_bench.rs @@ -1,5 +1,5 @@ use criterion::Criterion; -use hyper::Method; +use http::Method; use serde_json::Value; use tailcall::cli::runtime::NativeHttp; use tailcall::core::generator::{Generator, Input}; diff --git a/benches/handle_request_bench.rs b/benches/handle_request_bench.rs index c5e6640601b..38c135c996f 100644 --- a/benches/handle_request_bench.rs +++ b/benches/handle_request_bench.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use criterion::Criterion; -use hyper::Request; +use http::Request; use tailcall::cli::server::server_config::ServerConfig; use tailcall::core::async_graphql_hyper::GraphQLRequest; use tailcall::core::blueprint::Blueprint; diff --git a/benches/http_execute_bench.rs b/benches/http_execute_bench.rs index 4d30eff052f..c9a96edee69 100644 --- a/benches/http_execute_bench.rs +++ b/benches/http_execute_bench.rs @@ -1,5 +1,5 @@ use criterion::Criterion; -use hyper::Method; +use http::Method; use tailcall::cli::runtime::NativeHttp; use tailcall::core::blueprint::Blueprint; use tailcall::core::HttpIO; diff --git a/benches/impl_path_string_for_evaluation_context.rs b/benches/impl_path_string_for_evaluation_context.rs index d88e53e5de5..8fd725209a2 100644 --- a/benches/impl_path_string_for_evaluation_context.rs +++ b/benches/impl_path_string_for_evaluation_context.rs @@ -6,7 +6,7 @@ use std::time::Duration; use async_graphql::{Name, Value}; use async_trait::async_trait; use criterion::{BenchmarkId, Criterion}; -use headers::{HeaderMap, HeaderValue}; +use http::header::{HeaderMap, HeaderValue}; use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions}; use hyper::body::Bytes; use indexmap::IndexMap; diff --git a/benches/request_template_bench.rs b/benches/request_template_bench.rs index f9d6555c611..49d4bbd659c 100644 --- a/benches/request_template_bench.rs +++ b/benches/request_template_bench.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use criterion::{black_box, Criterion}; use derive_setters::Setters; -use headers::HeaderMap; +use http::header::HeaderMap; use serde_json::json; use tailcall::core::endpoint::Endpoint; use tailcall::core::has_headers::HasHeaders; diff --git a/src/cli/generator/generator.rs b/src/cli/generator/generator.rs index 40b426d79f4..0476ab13b49 100644 --- a/src/cli/generator/generator.rs +++ b/src/cli/generator/generator.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::Path; -use headers::{HeaderMap, HeaderName, HeaderValue}; +use http::header::{HeaderMap, HeaderName, HeaderValue}; use inquire::Confirm; use pathdiff::diff_paths; diff --git a/src/cli/javascript/codec.rs b/src/cli/javascript/codec.rs index 6be111f9f9f..a9eb083ee77 100644 --- a/src/cli/javascript/codec.rs +++ b/src/cli/javascript/codec.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use std::str::FromStr; -use headers::{HeaderName, HeaderValue}; +use http::header::{HeaderName, HeaderValue}; use rquickjs::{FromJs, IntoJs}; use super::create_header_map; @@ -205,7 +205,7 @@ mod test { use std::collections::BTreeMap; use anyhow::Result; - use headers::{HeaderMap, HeaderName, HeaderValue}; + use http::header::{HeaderMap, HeaderName, HeaderValue}; use hyper::body::Bytes; use pretty_assertions::assert_eq; use reqwest::Request; @@ -352,7 +352,7 @@ mod test { context.with(|ctx| { let js_response = WorkerResponse::try_from(Response { status: reqwest::StatusCode::OK, - headers: headers::HeaderMap::default(), + headers: HeaderMap::default(), body: Bytes::new(), }) .unwrap(); diff --git a/src/cli/javascript/mod.rs b/src/cli/javascript/mod.rs index e704ed0a1af..173928a1538 100644 --- a/src/cli/javascript/mod.rs +++ b/src/cli/javascript/mod.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use std::sync::Arc; -use headers::{HeaderName, HeaderValue}; +use http::header::{HeaderName, HeaderValue}; pub mod codec; diff --git a/src/core/async_graphql_hyper.rs b/src/core/async_graphql_hyper.rs index 54a62a48ea5..d12f9ecaae4 100644 --- a/src/core/async_graphql_hyper.rs +++ b/src/core/async_graphql_hyper.rs @@ -4,9 +4,9 @@ use std::hash::{Hash, Hasher}; use anyhow::Result; use async_graphql::parser::types::{ExecutableDocument, OperationType}; use async_graphql::{BatchResponse, Executor, Value}; -use headers::{HeaderMap, HeaderValue}; -use hyper::header::{CACHE_CONTROL, CONTENT_TYPE}; -use hyper::{Body, Response, StatusCode}; +use http::header::{HeaderMap, HeaderValue, CACHE_CONTROL, CONTENT_TYPE}; +use http::{Response, StatusCode}; +use hyper::Body; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use tailcall_hasher::TailcallHasher; @@ -270,7 +270,7 @@ impl GraphQLResponse { #[cfg(test)] mod tests { use async_graphql::{Name, Response, ServerError, Value}; - use hyper::StatusCode; + use http::StatusCode; use indexmap::IndexMap; use serde_json::json; diff --git a/src/core/auth/basic.rs b/src/core/auth/basic.rs index 31169bb73c5..1806d632058 100644 --- a/src/core/auth/basic.rs +++ b/src/core/auth/basic.rs @@ -43,7 +43,7 @@ impl BasicVerifier { #[cfg(test)] pub mod tests { - use headers::HeaderValue; + use http::header::HeaderValue; use super::*; diff --git a/src/core/blueprint/cors.rs b/src/core/blueprint/cors.rs index 92a21d5e1b5..3173907734b 100644 --- a/src/core/blueprint/cors.rs +++ b/src/core/blueprint/cors.rs @@ -1,7 +1,7 @@ use derive_setters::Setters; -use headers::{HeaderName, HeaderValue}; -use hyper::header; -use hyper::http::request::Parts; +use http::header; +use http::header::{HeaderName, HeaderValue}; +use http::request::Parts; use crate::core::config; use crate::core::valid::ValidationError; @@ -205,7 +205,7 @@ pub fn is_wildcard(header_value: &HeaderValue) -> bool { #[cfg(test)] mod tests { - use headers::HeaderValue; + use http::header::HeaderValue; use super::*; @@ -219,7 +219,7 @@ mod tests { assert_eq!( cors.allow_origin_to_header(origin.as_ref()), Some(( - hyper::header::ACCESS_CONTROL_ALLOW_ORIGIN, + header::ACCESS_CONTROL_ALLOW_ORIGIN, HeaderValue::from_static("https://example.com") )) ); diff --git a/src/core/blueprint/server.rs b/src/core/blueprint/server.rs index a9edd284c12..961dcceba47 100644 --- a/src/core/blueprint/server.rs +++ b/src/core/blueprint/server.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use std::time::Duration; use derive_setters::Setters; -use headers::{HeaderMap, HeaderName, HeaderValue}; +use http::header::{HeaderMap, HeaderName, HeaderValue}; use rustls_pki_types::{CertificateDer, PrivateKeyDer}; use super::Auth; diff --git a/src/core/blueprint/telemetry.rs b/src/core/blueprint/telemetry.rs index da429f5f075..6182b86fc12 100644 --- a/src/core/blueprint/telemetry.rs +++ b/src/core/blueprint/telemetry.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use headers::{HeaderMap, HeaderName, HeaderValue}; +use http::header::{HeaderMap, HeaderName, HeaderValue}; use url::Url; use super::TryFoldConfig; diff --git a/src/core/blueprint/upstream.rs b/src/core/blueprint/upstream.rs index b56295187c5..28ab604d521 100644 --- a/src/core/blueprint/upstream.rs +++ b/src/core/blueprint/upstream.rs @@ -60,7 +60,7 @@ impl TryFrom<&ConfigModule> for Upstream { if config_module.extensions().has_auth() { // force add auth specific headers to use it to make actual validation - allowed_headers.insert(hyper::header::AUTHORIZATION.to_string()); + allowed_headers.insert(http::header::AUTHORIZATION.to_string()); } get_batch(&config_upstream) diff --git a/src/core/config/cors.rs b/src/core/config/cors.rs index cb7cc4f234b..a3ac2ddfdf7 100644 --- a/src/core/config/cors.rs +++ b/src/core/config/cors.rs @@ -1,4 +1,4 @@ -use hyper::header; +use http::header; use serde::{Deserialize, Serialize}; use crate::core::http::Method; diff --git a/src/core/config/reader_context.rs b/src/core/config/reader_context.rs index 693e75fcfdc..9a0c8b590a0 100644 --- a/src/core/config/reader_context.rs +++ b/src/core/config/reader_context.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use headers::HeaderMap; +use http::header::HeaderMap; use crate::core::has_headers::HasHeaders; use crate::core::path::PathString; diff --git a/src/core/endpoint.rs b/src/core/endpoint.rs index 9f34aef8d82..d809096779b 100644 --- a/src/core/endpoint.rs +++ b/src/core/endpoint.rs @@ -1,5 +1,5 @@ use derive_setters::Setters; -use headers::HeaderMap; +use http::header::HeaderMap; use crate::core::config::Encoding; use crate::core::http::Method; diff --git a/src/core/graphql/request_template.rs b/src/core/graphql/request_template.rs index 8c469971ca7..1eb87f1cc8a 100644 --- a/src/core/graphql/request_template.rs +++ b/src/core/graphql/request_template.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use std::hash::{Hash, Hasher}; use derive_setters::Setters; -use headers::{HeaderMap, HeaderValue}; +use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; use crate::core::config::{GraphQLOperationType, KeyValue}; @@ -167,7 +167,7 @@ mod tests { use std::collections::HashSet; use async_graphql::Value; - use headers::HeaderMap; + use http::header::HeaderMap; use pretty_assertions::assert_eq; use serde_json::json; diff --git a/src/core/grpc/data_loader_request.rs b/src/core/grpc/data_loader_request.rs index 2619d34a8e5..a8af211bde7 100644 --- a/src/core/grpc/data_loader_request.rs +++ b/src/core/grpc/data_loader_request.rs @@ -54,7 +54,7 @@ impl DataLoaderRequest { mod tests { use std::collections::BTreeSet; - use headers::{HeaderMap, HeaderName, HeaderValue}; + use http::header::{HeaderMap, HeaderName, HeaderValue}; use pretty_assertions::assert_eq; use tailcall_fixtures::protobuf; use url::Url; diff --git a/src/core/grpc/request.rs b/src/core/grpc/request.rs index 36f791c4ba3..ba29a400402 100644 --- a/src/core/grpc/request.rs +++ b/src/core/grpc/request.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Result}; -use hyper::{HeaderMap, Method}; +use http::{HeaderMap, Method}; use reqwest::Request; use url::Url; @@ -45,9 +45,10 @@ mod tests { use anyhow::Result; use async_trait::async_trait; - use headers::HeaderMap; + use http::header::HeaderMap; + use http::{Method, StatusCode}; use hyper::body::Bytes; - use reqwest::{Method, Request, StatusCode}; + use reqwest::Request; use serde_json::json; use tailcall_fixtures::protobuf; use tonic::{Code, Status}; diff --git a/src/core/grpc/request_template.rs b/src/core/grpc/request_template.rs index ee55bbbc44a..6a0cbecbe2b 100644 --- a/src/core/grpc/request_template.rs +++ b/src/core/grpc/request_template.rs @@ -2,8 +2,7 @@ use std::hash::{Hash, Hasher}; use anyhow::Result; use derive_setters::Setters; -use headers::{HeaderMap, HeaderValue}; -use hyper::header::CONTENT_TYPE; +use http::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use tailcall_hasher::TailcallHasher; use url::Url; @@ -133,8 +132,8 @@ mod tests { use std::collections::HashSet; use derive_setters::Setters; - use headers::{HeaderMap, HeaderName, HeaderValue}; - use hyper::Method; + use http::header::{HeaderMap, HeaderName, HeaderValue}; + use http::Method; use pretty_assertions::assert_eq; use tailcall_fixtures::protobuf; diff --git a/src/core/has_headers.rs b/src/core/has_headers.rs index 6af560cc47d..78eaefafecc 100644 --- a/src/core/has_headers.rs +++ b/src/core/has_headers.rs @@ -1,4 +1,4 @@ -use headers::HeaderMap; +use http::header::HeaderMap; use crate::core::ir::{EvalContext, ResolverContextLike}; diff --git a/src/core/helpers/headers.rs b/src/core/helpers/headers.rs index acde9d17ac8..38280ed1bd9 100644 --- a/src/core/helpers/headers.rs +++ b/src/core/helpers/headers.rs @@ -1,4 +1,4 @@ -use headers::HeaderName; +use http::header::HeaderName; use crate::core::config::KeyValue; use crate::core::mustache::Mustache; @@ -24,7 +24,7 @@ pub fn to_mustache_headers(headers: &[KeyValue]) -> Valid) -> Option { - let header = res.headers.get(hyper::header::CACHE_CONTROL)?; + let header = res.headers.get(http::header::CACHE_CONTROL)?; let value = header.to_str().ok()?; CacheControl::from_value(value) @@ -15,7 +15,7 @@ mod tests { use std::time::Duration; use cache_control::Cachability; - use headers::HeaderMap; + use http::header::HeaderMap; use crate::core::http::Response; diff --git a/src/core/http/data_loader_request.rs b/src/core/http/data_loader_request.rs index 72635e92195..b386f8daeaa 100644 --- a/src/core/http/data_loader_request.rs +++ b/src/core/http/data_loader_request.rs @@ -78,7 +78,7 @@ impl Deref for DataLoaderRequest { #[cfg(test)] mod tests { - use headers::{HeaderName, HeaderValue}; + use http::header::{HeaderName, HeaderValue}; use super::*; fn create_request_with_headers(url: &str, headers: Vec<(&str, &str)>) -> reqwest::Request { diff --git a/src/core/http/method.rs b/src/core/http/method.rs index fe6671b91d2..2e1345edaae 100644 --- a/src/core/http/method.rs +++ b/src/core/http/method.rs @@ -27,17 +27,17 @@ pub enum Method { } impl Method { - pub fn to_hyper(self) -> hyper::Method { + pub fn to_hyper(self) -> http::Method { match self { - Method::GET => hyper::Method::GET, - Method::POST => hyper::Method::POST, - Method::PUT => hyper::Method::PUT, - Method::PATCH => hyper::Method::PATCH, - Method::DELETE => hyper::Method::DELETE, - Method::HEAD => hyper::Method::HEAD, - Method::OPTIONS => hyper::Method::OPTIONS, - Method::CONNECT => hyper::Method::CONNECT, - Method::TRACE => hyper::Method::TRACE, + Method::GET => http::Method::GET, + Method::POST => http::Method::POST, + Method::PUT => http::Method::PUT, + Method::PATCH => http::Method::PATCH, + Method::DELETE => http::Method::DELETE, + Method::HEAD => http::Method::HEAD, + Method::OPTIONS => http::Method::OPTIONS, + Method::CONNECT => http::Method::CONNECT, + Method::TRACE => http::Method::TRACE, } } } diff --git a/src/core/http/mod.rs b/src/core/http/mod.rs index 6eb81f273f1..69967ed0986 100644 --- a/src/core/http/mod.rs +++ b/src/core/http/mod.rs @@ -1,7 +1,7 @@ pub use cache::*; pub use data_loader::*; pub use data_loader_request::*; -use headers::HeaderValue; +use http::header::HeaderValue; pub use method::Method; pub use query_encoder::QueryEncoder; pub use request_context::RequestContext; diff --git a/src/core/http/request_context.rs b/src/core/http/request_context.rs index 9d3517a94e7..cd77ffc979e 100644 --- a/src/core/http/request_context.rs +++ b/src/core/http/request_context.rs @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex}; use async_graphql_value::ConstValue; use cache_control::{Cachability, CacheControl}; use derive_setters::Setters; -use headers::{HeaderMap, HeaderName, HeaderValue}; +use http::header::{HeaderMap, HeaderName, HeaderValue}; use crate::core::app_context::AppContext; use crate::core::auth::context::AuthContext; diff --git a/src/core/http/request_handler.rs b/src/core/http/request_handler.rs index da55f9a703e..8f105ef2f67 100644 --- a/src/core/http/request_handler.rs +++ b/src/core/http/request_handler.rs @@ -4,11 +4,10 @@ use std::sync::Arc; use anyhow::Result; use async_graphql::ServerError; -use headers::{HeaderMap, HeaderValue}; -use hyper::header::{self, CONTENT_TYPE}; -use hyper::http::request::Parts; -use hyper::http::Method; -use hyper::{Body, Request, Response, StatusCode}; +use http::header::{self, HeaderMap, HeaderValue, CONTENT_TYPE}; +use http::request::Parts; +use http::{Method, Request, Response, StatusCode}; +use hyper::Body; use opentelemetry::trace::SpanKind; use opentelemetry_semantic_conventions::trace::{HTTP_REQUEST_METHOD, HTTP_ROUTE}; use prometheus::{Encoder, ProtobufEncoder, TextEncoder, TEXT_FORMAT}; @@ -78,7 +77,7 @@ fn update_cache_control_header( } pub fn update_response_headers( - resp: &mut hyper::Response, + resp: &mut Response, req_ctx: &RequestContext, app_ctx: &AppContext, ) { @@ -306,10 +305,10 @@ async fn handle_request_inner( // NOTE: // The first check for the route should be for `/graphql` // This is always going to be the most used route. - hyper::Method::POST if req.uri().path() == graphql_endpoint => { + Method::POST if req.uri().path() == graphql_endpoint => { graphql_request::(req, &app_ctx, req_counter).await } - hyper::Method::POST + Method::POST if app_ctx.blueprint.server.enable_showcase && req.uri().path() == "/showcase/graphql" => { @@ -321,14 +320,14 @@ async fn handle_request_inner( graphql_request::(req, &Arc::new(app_ctx), req_counter).await } - hyper::Method::GET if req.uri().path() == health_check_endpoint => { + Method::GET if req.uri().path() == health_check_endpoint => { let status_response = Response::builder() .status(StatusCode::OK) .header(CONTENT_TYPE, "application/json") .body(Body::from(r#"{"message": "ready"}"#))?; Ok(status_response) } - hyper::Method::GET => { + Method::GET => { if let Some(TelemetryExporter::Prometheus(prometheus)) = app_ctx.blueprint.telemetry.export.as_ref() { @@ -450,7 +449,7 @@ mod test { fn test_create_allowed_headers() { use std::collections::BTreeSet; - use headers::{HeaderMap, HeaderValue}; + use http::header::{HeaderMap, HeaderValue}; use super::create_allowed_headers; diff --git a/src/core/http/request_template.rs b/src/core/http/request_template.rs index 7be3b09d095..3c3c7ae1320 100644 --- a/src/core/http/request_template.rs +++ b/src/core/http/request_template.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::hash::{Hash, Hasher}; use derive_setters::Setters; -use headers::{HeaderMap, HeaderValue}; +use http::header::{HeaderMap, HeaderValue}; use tailcall_hasher::TailcallHasher; use url::Url; @@ -308,7 +308,7 @@ mod tests { use std::borrow::Cow; use derive_setters::Setters; - use headers::{HeaderMap, HeaderName}; + use http::header::{HeaderMap, HeaderName}; use pretty_assertions::assert_eq; use serde_json::json; @@ -646,7 +646,7 @@ mod tests { } mod endpoint { - use headers::HeaderMap; + use http::header::HeaderMap; use serde_json::json; use crate::core::http::request_template::tests::Context; @@ -843,7 +843,7 @@ mod tests { mod cache_key { use std::collections::HashSet; - use headers::HeaderMap; + use http::header::HeaderMap; use serde_json::json; use crate::core::http::request_template::tests::Context; diff --git a/src/core/http/response.rs b/src/core/http/response.rs index 00b9c462725..bfbbb22bc03 100644 --- a/src/core/http/response.rs +++ b/src/core/http/response.rs @@ -56,7 +56,7 @@ impl Response { Ok(Response { status, headers, body }) } - pub async fn from_hyper(resp: hyper::Response) -> Result { + 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?; @@ -156,9 +156,9 @@ impl Response { } } -impl From> for hyper::Response { +impl From> for http::Response { fn from(resp: Response) -> Self { - let mut response = hyper::Response::new(Body::from(resp.body)); + let mut response = http::Response::new(Body::from(resp.body)); *response.headers_mut() = resp.headers; *response.status_mut() = resp.status; response diff --git a/src/core/http/showcase.rs b/src/core/http/showcase.rs index e2910e8e117..413cd22890c 100644 --- a/src/core/http/showcase.rs +++ b/src/core/http/showcase.rs @@ -2,7 +2,8 @@ use std::collections::HashMap; use anyhow::Result; use async_graphql::ServerError; -use hyper::{Body, Request, Response}; +use http::{Request, Response}; +use hyper::Body; use serde::de::DeserializeOwned; use url::Url; @@ -72,7 +73,7 @@ pub async fn create_app_ctx( mod tests { use std::sync::Arc; - use hyper::Request; + use http::Request; use serde_json::json; use crate::core::async_graphql_hyper::GraphQLRequest; diff --git a/src/core/http/telemetry.rs b/src/core/http/telemetry.rs index f018ce39c26..14fa9d7961c 100644 --- a/src/core/http/telemetry.rs +++ b/src/core/http/telemetry.rs @@ -1,5 +1,6 @@ use anyhow::Result; -use hyper::{Body, Request, Response}; +use http::{Request, Response}; +use hyper::Body; use once_cell::sync::Lazy; use opentelemetry::metrics::Counter; use opentelemetry::KeyValue; diff --git a/src/core/ir/eval_context.rs b/src/core/ir/eval_context.rs index 5986e5d057b..1a79f561bb3 100644 --- a/src/core/ir/eval_context.rs +++ b/src/core/ir/eval_context.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use std::sync::Arc; use async_graphql::{ServerError, Value}; -use headers::HeaderMap; +use http::header::HeaderMap; use super::{GraphQLOperationContext, RelatedFields, ResolverContextLike, SelectionField}; use crate::core::document::print_directives; diff --git a/src/core/path.rs b/src/core/path.rs index eaffdcb0cdb..ef645d7576a 100644 --- a/src/core/path.rs +++ b/src/core/path.rs @@ -137,7 +137,7 @@ mod tests { use std::sync::Arc; use async_graphql_value::{ConstValue as Value, Name, Number}; - use headers::{HeaderMap, HeaderValue}; + use http::header::{HeaderMap, HeaderValue}; use indexmap::IndexMap; use once_cell::sync::Lazy; diff --git a/src/core/proto_reader/fetch.rs b/src/core/proto_reader/fetch.rs index d72ce4a0ee4..7267918fe08 100644 --- a/src/core/proto_reader/fetch.rs +++ b/src/core/proto_reader/fetch.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use anyhow::{Context, Result}; use base64::prelude::BASE64_STANDARD; use base64::Engine; -use headers::HeaderName; +use http::header::HeaderName; use nom::AsBytes; use prost::Message; use prost_reflect::prost_types::{FileDescriptorProto, FileDescriptorSet}; diff --git a/src/core/rest/endpoint.rs b/src/core/rest/endpoint.rs index 2131a1f15cf..98b730a534f 100644 --- a/src/core/rest/endpoint.rs +++ b/src/core/rest/endpoint.rs @@ -284,7 +284,8 @@ mod tests { use async_graphql::Variables; use async_graphql_value::{ConstValue, Name}; - use hyper::{Body, Method, Request, Uri, Version}; + use http::{Method, Request, Uri, Version}; + use hyper::Body; use maplit::btreemap; use pretty_assertions::assert_eq; @@ -292,7 +293,7 @@ mod tests { use crate::core::rest::endpoint::tests::TEST_QUERY; use crate::core::rest::endpoint::Endpoint; - fn test_request(method: Method, uri: &str) -> Result> { + fn test_request(method: Method, uri: &str) -> Result> { Ok(Request::builder() .method(method) .uri(Uri::from_str(uri)?) diff --git a/src/core/rest/error.rs b/src/core/rest/error.rs index 4876ced80d8..c23fda1aa74 100644 --- a/src/core/rest/error.rs +++ b/src/core/rest/error.rs @@ -46,10 +46,10 @@ pub enum Error { ParseGraphQL(async_graphql::parser::Error), #[error("Hyper HTTP Invalid URI Error: {}", _0)] - HyperHttpInvalidUri(hyper::http::uri::InvalidUri), + HyperHttpInvalidUri(http::uri::InvalidUri), #[error("Hyper HTTP Error: {}", _0)] - HyperHttp(hyper::http::Error), + HyperHttp(http::Error), #[error("Hyper Error: {}", _0)] Hyper(hyper::Error), diff --git a/src/core/rest/mod.rs b/src/core/rest/mod.rs index 812c30060a2..2a086d54133 100644 --- a/src/core/rest/mod.rs +++ b/src/core/rest/mod.rs @@ -11,5 +11,5 @@ mod typed_variables; pub use endpoint_set::{Checked, EndpointSet, Unchecked}; -type Request = hyper::Request; +type Request = http::Request; pub use error::{Error, Result}; diff --git a/src/core/valid/error.rs b/src/core/valid/error.rs index 961ad852ef1..d4350f1d7a4 100644 --- a/src/core/valid/error.rs +++ b/src/core/valid/error.rs @@ -125,8 +125,8 @@ impl From> for ValidationError for ValidationError { - fn from(error: hyper::header::InvalidHeaderValue) -> Self { +impl From for ValidationError { + fn from(error: http::header::InvalidHeaderValue) -> Self { ValidationError::new(error.to_string()) } } diff --git a/src/core/worker/error.rs b/src/core/worker/error.rs index b6d829d145e..3490fea46aa 100644 --- a/src/core/worker/error.rs +++ b/src/core/worker/error.rs @@ -19,7 +19,7 @@ pub enum Error { RequestCloneFailed, #[debug(fmt = "Hyper Header To Str Error: {}", _0)] - HyperHeaderStr(Arc), + HyperHeaderStr(Arc), #[debug(fmt = "JS Runtime Stopped Error")] JsRuntimeStopped, @@ -66,8 +66,8 @@ impl From for Error { } } -impl From for Error { - fn from(error: hyper::header::ToStrError) -> Self { +impl From for Error { + fn from(error: http::header::ToStrError) -> Self { Error::HyperHeaderStr(Arc::new(error)) } } diff --git a/tailcall-aws-lambda/Cargo.toml b/tailcall-aws-lambda/Cargo.toml index a1d4c56780a..5aa61d0ef45 100644 --- a/tailcall-aws-lambda/Cargo.toml +++ b/tailcall-aws-lambda/Cargo.toml @@ -26,5 +26,6 @@ anyhow = "1.0.82" async-trait = "0.1.80" async-graphql-value = "7.0.3" hyper = { version = "0.14.28", default-features = false } +http = { workspace = true } reqwest = { version = "0.11", default-features = false } tailcall = { path = "..", default-features = false } diff --git a/tailcall-aws-lambda/src/http.rs b/tailcall-aws-lambda/src/http.rs index a6dd7734c7d..8541a2f898f 100644 --- a/tailcall-aws-lambda/src/http.rs +++ b/tailcall-aws-lambda/src/http.rs @@ -40,18 +40,18 @@ impl HttpIO for LambdaHttp { } } -pub fn to_request(req: lambda_http::Request) -> anyhow::Result> { +pub fn to_request(req: lambda_http::Request) -> anyhow::Result> { // TODO: Update hyper to 1.0 to make conversions easier - let method: hyper::Method = match req.method().to_owned() { - lambda_http::http::Method::CONNECT => hyper::Method::CONNECT, - lambda_http::http::Method::DELETE => hyper::Method::DELETE, - lambda_http::http::Method::GET => hyper::Method::GET, - lambda_http::http::Method::HEAD => hyper::Method::HEAD, - lambda_http::http::Method::OPTIONS => hyper::Method::OPTIONS, - lambda_http::http::Method::PATCH => hyper::Method::PATCH, - lambda_http::http::Method::POST => hyper::Method::POST, - lambda_http::http::Method::PUT => hyper::Method::PUT, - lambda_http::http::Method::TRACE => hyper::Method::TRACE, + let method: http::Method = match req.method().to_owned() { + lambda_http::http::Method::CONNECT => http::Method::CONNECT, + lambda_http::http::Method::DELETE => http::Method::DELETE, + lambda_http::http::Method::GET => http::Method::GET, + lambda_http::http::Method::HEAD => http::Method::HEAD, + lambda_http::http::Method::OPTIONS => http::Method::OPTIONS, + lambda_http::http::Method::PATCH => http::Method::PATCH, + lambda_http::http::Method::POST => http::Method::POST, + lambda_http::http::Method::PUT => http::Method::PUT, + lambda_http::http::Method::TRACE => http::Method::TRACE, _ => unreachable!(), }; @@ -68,11 +68,11 @@ pub fn to_request(req: lambda_http::Request) -> anyhow::Result anyhow::Result, + res: http::Response, ) -> Result, lambda_http::http::Error> { // TODO: Update hyper to 1.0 to make conversions easier let mut build = lambda_http::Response::builder().status(res.status().as_u16()); @@ -102,6 +102,7 @@ pub fn init_http() -> Arc { mod tests { use lambda_http::http::{Method, Request, StatusCode, Uri}; use lambda_http::Body; + extern crate http; use super::*; @@ -115,7 +116,7 @@ mod tests { .body(Body::from("Hello, world!")) .unwrap(); let hyper_req = to_request(req).unwrap(); - assert_eq!(hyper_req.method(), hyper::Method::GET); + assert_eq!(hyper_req.method(), http::Method::GET); assert_eq!(hyper_req.uri(), "http://example.com/"); assert_eq!( hyper_req.headers().get("content-type").unwrap(), @@ -129,7 +130,7 @@ mod tests { #[tokio::test] async fn test_to_response() { - let res = hyper::Response::builder() + let res = http::Response::builder() .status(200) .header("content-type", "application/json") .header("x-custom-header", "custom-value") diff --git a/tailcall-cloudflare/Cargo.toml b/tailcall-cloudflare/Cargo.toml index 0462c793fa2..f6ac32f117c 100644 --- a/tailcall-cloudflare/Cargo.toml +++ b/tailcall-cloudflare/Cargo.toml @@ -25,4 +25,5 @@ serde_qs = "0.13.0" console_error_panic_hook = "0.1.7" protox = "0.7.0" async-graphql-value = "7.0.3" +http = { workspace = true } diff --git a/tailcall-cloudflare/src/handle.rs b/tailcall-cloudflare/src/handle.rs index c7abc4e95eb..0961d0c9144 100644 --- a/tailcall-cloudflare/src/handle.rs +++ b/tailcall-cloudflare/src/handle.rs @@ -2,7 +2,8 @@ use std::collections::HashMap; use std::rc::Rc; use std::sync::{Arc, RwLock}; -use hyper::{Body, Request, Response}; +use http::{Request, Response}; +use hyper::Body; use lazy_static::lazy_static; use tailcall::core::app_context::AppContext; use tailcall::core::async_graphql_hyper::GraphQLRequest; diff --git a/tailcall-cloudflare/src/http.rs b/tailcall-cloudflare/src/http.rs index 3f87fe43773..27aa6da46e7 100644 --- a/tailcall-cloudflare/src/http.rs +++ b/tailcall-cloudflare/src/http.rs @@ -7,6 +7,8 @@ use tailcall::core::HttpIO; use crate::to_anyhow; +extern crate http; + #[derive(Clone)] pub struct CloudflareHttp { client: Client, @@ -48,7 +50,7 @@ impl HttpIO for CloudflareHttp { } } -pub async fn to_response(response: hyper::Response) -> Result { +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?; @@ -66,30 +68,28 @@ pub async fn to_response(response: hyper::Response) -> Result Result { +pub fn to_method(method: worker::Method) -> Result { let method = &*method.to_string().to_uppercase(); match method { - "GET" => Ok(hyper::Method::GET), - "POST" => Ok(hyper::Method::POST), - "PUT" => Ok(hyper::Method::PUT), - "DELETE" => Ok(hyper::Method::DELETE), - "HEAD" => Ok(hyper::Method::HEAD), - "OPTIONS" => Ok(hyper::Method::OPTIONS), - "PATCH" => Ok(hyper::Method::PATCH), - "CONNECT" => Ok(hyper::Method::CONNECT), - "TRACE" => Ok(hyper::Method::TRACE), + "GET" => Ok(http::Method::GET), + "POST" => Ok(http::Method::POST), + "PUT" => Ok(http::Method::PUT), + "DELETE" => Ok(http::Method::DELETE), + "HEAD" => Ok(http::Method::HEAD), + "OPTIONS" => Ok(http::Method::OPTIONS), + "PATCH" => Ok(http::Method::PATCH), + "CONNECT" => Ok(http::Method::CONNECT), + "TRACE" => Ok(http::Method::TRACE), method => Err(anyhow!("Unsupported HTTP method: {}", method)), } } -pub async fn to_request(mut req: worker::Request) -> Result> { +pub async fn to_request(mut req: worker::Request) -> Result> { let body = req.text().await.map_err(to_anyhow)?; let method = req.method(); let uri = req.url().map_err(to_anyhow)?.as_str().to_string(); let headers = req.headers(); - let mut builder = hyper::Request::builder() - .method(to_method(method)?) - .uri(uri); + let mut builder = http::Request::builder().method(to_method(method)?).uri(uri); for (k, v) in headers { builder = builder.header(k, v); } diff --git a/tailcall-tracker/Cargo.toml b/tailcall-tracker/Cargo.toml index e7a73a06317..0fda8c0a119 100644 --- a/tailcall-tracker/Cargo.toml +++ b/tailcall-tracker/Cargo.toml @@ -26,4 +26,4 @@ chrono = "0.4.38" whoami = "1.5.2" strum = "0.26.3" convert_case = { workspace = true } -headers = { workspace = true } +http = { workspace = true } diff --git a/tailcall-tracker/src/collect/ga.rs b/tailcall-tracker/src/collect/ga.rs index cb7799671ac..0bdf34d61fc 100644 --- a/tailcall-tracker/src/collect/ga.rs +++ b/tailcall-tracker/src/collect/ga.rs @@ -1,4 +1,4 @@ -use headers::{HeaderName, HeaderValue}; +use http::header::{HeaderName, HeaderValue}; use serde::{Deserialize, Serialize}; use super::super::Result; diff --git a/tailcall-tracker/src/collect/posthog.rs b/tailcall-tracker/src/collect/posthog.rs index e947875afa5..3d12b0403e0 100644 --- a/tailcall-tracker/src/collect/posthog.rs +++ b/tailcall-tracker/src/collect/posthog.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use chrono::NaiveDateTime; -use headers::{HeaderName, HeaderValue}; +use http::header::{HeaderName, HeaderValue}; use serde::Serialize; use serde_json::Value; diff --git a/tailcall-upstream-grpc/Cargo.toml b/tailcall-upstream-grpc/Cargo.toml index b57a981e274..97b6b4ecb5c 100644 --- a/tailcall-upstream-grpc/Cargo.toml +++ b/tailcall-upstream-grpc/Cargo.toml @@ -33,6 +33,7 @@ tracing-opentelemetry = "0.24.0" tracing-subscriber = "0.3.18" derive_more = { workspace = true } thiserror = { workspace = true } +http = { workspace = true } [build-dependencies] protoc-bin-vendored = "3.0.0" diff --git a/tailcall-upstream-grpc/src/error.rs b/tailcall-upstream-grpc/src/error.rs index 47f59bbb2b4..4a1453ac717 100644 --- a/tailcall-upstream-grpc/src/error.rs +++ b/tailcall-upstream-grpc/src/error.rs @@ -1,7 +1,7 @@ use std::env::VarError; use derive_more::From; -use hyper::header::InvalidHeaderValue; +use http::header::InvalidHeaderValue; use opentelemetry::trace::TraceError; use tracing::subscriber::SetGlobalDefaultError; diff --git a/tailcall-upstream-grpc/src/main.rs b/tailcall-upstream-grpc/src/main.rs index 1d8403ddb28..0ab9974d239 100644 --- a/tailcall-upstream-grpc/src/main.rs +++ b/tailcall-upstream-grpc/src/main.rs @@ -3,7 +3,7 @@ mod error; use std::sync::{Arc, Mutex}; use error::Error; -use headers::{HeaderMap, HeaderName, HeaderValue}; +use http::header::{HeaderMap, HeaderName, HeaderValue}; use news::news_service_server::{NewsService, NewsServiceServer}; use news::{MultipleNewsId, News, NewsId, NewsList}; use once_cell::sync::Lazy; diff --git a/tailcall-wasm/Cargo.toml b/tailcall-wasm/Cargo.toml index 803b208bc24..e007c506243 100644 --- a/tailcall-wasm/Cargo.toml +++ b/tailcall-wasm/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -tailcall = {path = "..", default-features = false} +tailcall = { path = "..", default-features = false } wasm-bindgen = "0.2.92" wasm-bindgen-futures = "0.4.42" anyhow = "1.0.83" @@ -23,6 +23,7 @@ dashmap = "6.0.0" async-graphql-value = "7.0.5" serde_json = "1.0.117" url = "2.5.0" +http = { workspace = true } [dev-dependencies] wasm-bindgen-test = "0.3.42" diff --git a/tailcall-wasm/src/lib.rs b/tailcall-wasm/src/lib.rs index fbcde1c6ac3..4ec3e5a3dd2 100644 --- a/tailcall-wasm/src/lib.rs +++ b/tailcall-wasm/src/lib.rs @@ -17,6 +17,8 @@ mod file; mod http; mod runtime; +extern crate http as http_crate; + #[wasm_bindgen] pub struct TailcallExecutor { app_context: Arc, @@ -29,8 +31,8 @@ impl TailcallExecutor { } async fn execute_inner(&self, query: String) -> anyhow::Result { let body = json!({"query":query}).to_string(); - let req = - hyper::Request::post("http://fake.host/graphql").body(hyper::body::Body::from(body))?; + let req = http_crate::Request::post("http://fake.host/graphql") + .body(hyper::body::Body::from(body))?; let resp = handle_request::(req, self.app_context.clone()).await?; tracing::debug!("{:#?}", resp); diff --git a/tests/core/http.rs b/tests/core/http.rs index 536a51a3dc5..09e8020ea37 100644 --- a/tests/core/http.rs +++ b/tests/core/http.rs @@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use anyhow::anyhow; -use headers::{HeaderName, HeaderValue}; +use http::header::{HeaderName, HeaderValue}; use hyper::body::Bytes; use tailcall::core::http::Response; use tailcall::core::HttpIO; diff --git a/tests/core/spec.rs b/tests/core/spec.rs index 8215f928d44..be287d044c0 100644 --- a/tests/core/spec.rs +++ b/tests/core/spec.rs @@ -8,7 +8,8 @@ use std::{fs, panic}; use anyhow::Context; use colored::Colorize; use futures_util::future::join_all; -use hyper::{Body, Request}; +use http::Request; +use hyper::Body; use serde::{Deserialize, Serialize}; use tailcall::core::app_context::AppContext; use tailcall::core::async_graphql_hyper::{GraphQLBatchRequest, GraphQLRequest}; @@ -307,7 +308,7 @@ pub async fn load_and_test_execution_spec(path: &Path) -> anyhow::Result<()> { async fn run_test( app_ctx: Arc, request: &APIRequest, -) -> anyhow::Result> { +) -> anyhow::Result> { let body = request .body .as_ref()