From 3658a737e00bdd38eb3b0adc3c4709f58569037f Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Thu, 1 Aug 2024 18:12:06 +0300 Subject: [PATCH 1/2] fix: parsing envs and headers arg --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b977ed..24148e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,13 +53,13 @@ struct HttpRunArgs { #[arg(short, long)] wasm: PathBuf, /// Environment variable list - #[arg(long, value_parser = parse_key_value::< String, String >)] + #[arg(long, value_parser = parse_key_value::)] envs: Option>, /// Add header from original request #[arg(long = "propagate-header", num_args = 0..)] propagate_headers: Vec, /// Execution context headers added to request - #[arg(long, value_parser = parse_key_value::< String, String >)] + #[arg(long, value_parser = parse_key_value::< SmolStr, SmolStr >)] headers: Option>, /// Append sample Geo PoP headers #[arg(long, default_value = "false")] From 9a20b713483b7aeff5ba9e9f7235018f461ce5b4 Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Thu, 1 Aug 2024 23:06:04 +0300 Subject: [PATCH 2/2] fix: changed hyper::Error to anyhow::Error --- Cargo.toml | 2 +- crates/http-service/src/executor/mod.rs | 10 +++++----- crates/http-service/src/executor/wasi_http.rs | 9 ++++----- crates/http-service/src/lib.rs | 10 +++++----- src/main.rs | 3 +-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3ae640..f99b174 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["crates/*"] resolver = "2" [workspace.package] -version = "0.5.1" +version = "0.5.2" edition = "2021" publish = false authors = ["FastEdge Development Team"] diff --git a/crates/http-service/src/executor/mod.rs b/crates/http-service/src/executor/mod.rs index 5bba2e0..6767b80 100644 --- a/crates/http-service/src/executor/mod.rs +++ b/crates/http-service/src/executor/mod.rs @@ -3,7 +3,7 @@ mod wasi_http; use std::collections::HashMap; use std::time::{Duration, Instant}; -use anyhow::{anyhow, bail, Context, Error, Result}; +use anyhow::{anyhow, bail, Context, Result}; use async_trait::async_trait; use bytesize::ByteSize; use http::{HeaderMap, HeaderValue, Method, Response}; @@ -30,7 +30,7 @@ pub trait HttpExecutor { async fn execute( &self, req: hyper::Request, - ) -> Result<(Response>, Duration, ByteSize)> + ) -> Result<(Response>, Duration, ByteSize)> where B: BodyExt + Send, ::Data: Send; @@ -62,7 +62,7 @@ where async fn execute( &self, req: hyper::Request, - ) -> Result<(Response>, Duration, ByteSize)> + ) -> Result<(Response>, Duration, ByteSize)> where B: BodyExt + Send, ::Data: Send, @@ -93,7 +93,7 @@ where async fn execute_impl( &self, req: hyper::Request, - ) -> Result<(Response>, ByteSize)> + ) -> Result<(Response>, ByteSize)> where B: BodyExt + Send, ::Data: Send, @@ -185,7 +185,7 @@ where .body .map(|b| Full::from(b).map_err(|never| match never {}).boxed()) .unwrap_or_default(); - builder.body(body).map(|r| (r, used)).map_err(Error::msg) + builder.body(body).map(|r| (r, used)).map_err(anyhow::Error::msg) } fn get_properties(headers: &HeaderMap) -> HashMap { diff --git a/crates/http-service/src/executor/wasi_http.rs b/crates/http-service/src/executor/wasi_http.rs index de56061..4c95d76 100644 --- a/crates/http-service/src/executor/wasi_http.rs +++ b/crates/http-service/src/executor/wasi_http.rs @@ -10,7 +10,7 @@ use http_body_util::{BodyExt, Full}; use hyper::body::{Body, Bytes}; use smol_str::ToSmolStr; use tracing::error; -use wasmtime_wasi_http::WasiHttpView; +use wasmtime_wasi_http::{ WasiHttpView}; use http_backend::Backend; use runtime::store::StoreBuilder; @@ -35,7 +35,7 @@ where async fn execute( &self, req: hyper::Request, - ) -> anyhow::Result<(Response>, Duration, ByteSize)> + ) -> anyhow::Result<(Response>, Duration, ByteSize)> where B: BodyExt + Send, ::Data: Send, @@ -66,7 +66,7 @@ where async fn execute_impl( &self, req: hyper::Request, - ) -> anyhow::Result<(Response>, ByteSize)> + ) -> anyhow::Result<(Response>, ByteSize)> where B: BodyExt, { @@ -168,8 +168,7 @@ where match receiver.await { Ok(Ok(resp)) => { let (parts, body) = resp.into_parts(); - let body = body.collect().await.context("response body")?.to_bytes(); - let body = Full::new(body).map_err(|never| match never {}).boxed(); + let body = body.map_err(anyhow::Error::msg).boxed(); let used = task.await.context("task await")?.context("byte size")?; Ok((Response::from_parts(parts, body), used)) } diff --git a/crates/http-service/src/lib.rs b/crates/http-service/src/lib.rs index a3bb232..eb1b255 100644 --- a/crates/http-service/src/lib.rs +++ b/crates/http-service/src/lib.rs @@ -181,7 +181,7 @@ where &self, request_id: &str, mut request: Request, - ) -> Result>> + ) -> Result>> where B: BodyExt + Send, ::Data: Send, @@ -407,7 +407,7 @@ fn remote_traceparent(req: &Request) -> String { } /// Creates an HTTP 500 response. -fn internal_fastedge_error(msg: &'static str) -> Result>> { +fn internal_fastedge_error(msg: &'static str) -> Result>> { Ok(Response::builder().status(FASTEDGE_INTERNAL_ERROR).body( Full::new(Bytes::from(format!("fastedge: {}", msg))) .map_err(|never| match never {}) @@ -416,7 +416,7 @@ fn internal_fastedge_error(msg: &'static str) -> Result Result>> { +fn not_found() -> Result>> { Ok(Response::builder().status(StatusCode::NOT_FOUND).body( Full::new(Bytes::from("fastedge: Unknown app")) .map_err(|never| match never {}) @@ -425,14 +425,14 @@ fn not_found() -> Result>> { } /// Creates an HTTP 429 response. -fn too_many_requests() -> Result>> { +fn too_many_requests() -> Result>> { Ok(Response::builder() .status(StatusCode::TOO_MANY_REQUESTS) .body(Empty::new().map_err(|never| match never {}).boxed())?) } /// Creates an HTTP 406 response. -fn not_acceptable() -> Result>> { +fn not_acceptable() -> Result>> { Ok(Response::builder() .status(StatusCode::NOT_ACCEPTABLE) .body(Empty::new().map_err(|never| match never {}).boxed())?) diff --git a/src/main.rs b/src/main.rs index 24148e8..251e168 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,6 @@ use http_service::executor::{ use http_service::state::HttpState; use http_service::{ContextHeaders, HttpConfig, HttpService}; use hyper::body::{Body, Bytes}; -use hyper::Error; use hyper_tls::HttpsConnector; use hyper_util::client::legacy::connect::HttpConnector; use runtime::app::Status; @@ -215,7 +214,7 @@ impl HttpExecutor for CliExecutor { async fn execute( &self, req: Request, - ) -> anyhow::Result<(Response>, Duration, ByteSize)> + ) -> anyhow::Result<(Response>, Duration, ByteSize)> where B: BodyExt + Send, ::Data: Send,