diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f7526..627f0a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ -# Changelog +## [0.11.9] - 2025-08-29 -All notable changes to this project will be documented in this file. +### 🐛 Bug Fixes + +- Use direct backend for fastedge cli +## [0.11.8] - 2025-06-05 +### ⚙️ Miscellaneous Tasks + +- Release ## [0.11.7] - 2025-04-25 ### 🚀 Features @@ -11,7 +17,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.6] - 2025-04-04 ### 🐛 Bug Fixes @@ -21,7 +26,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.5] - 2025-04-03 ### 🐛 Bug Fixes @@ -31,7 +35,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.4] - 2025-04-02 ### 🚜 Refactor @@ -41,7 +44,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.3] - 2025-04-02 ### 🐛 Bug Fixes @@ -51,7 +53,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.2] - 2025-04-02 ### 🐛 Bug Fixes @@ -61,7 +62,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.1] - 2025-04-01 ### 🐛 Bug Fixes @@ -71,7 +71,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.11.0] - 2025-04-01 ### 🐛 Bug Fixes @@ -84,7 +83,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.10.2] - 2025-02-21 ### 🐛 Bug Fixes @@ -94,7 +92,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.10.1] - 2025-02-20 ### 🐛 Bug Fixes @@ -109,7 +106,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.10.0] - 2025-02-19 ### 🚜 Refactor @@ -120,7 +116,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.9.4] - 2025-01-21 ### 🐛 Bug Fixes @@ -131,7 +126,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.9.3] - 2025-01-20 ### 🐛 Bug Fixes @@ -144,7 +138,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.9.2] - 2024-12-18 ### 🚀 Features @@ -154,7 +147,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.9.1] - 2024-12-06 ### 🐛 Bug Fixes @@ -166,7 +158,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.9.0] - 2024-11-22 ### 🐛 Bug Fixes @@ -178,13 +169,11 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.8.1] - 2024-11-11 ### ⚙️ Miscellaneous Tasks - Release - ## [0.8.0] - 2024-10-21 ### 🚀 Features @@ -199,7 +188,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.7.0] - 2024-10-16 ### 🚜 Refactor @@ -209,7 +197,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.6.0] - 2024-09-20 ### 🐛 Bug Fixes @@ -220,7 +207,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.5.7] - 2024-09-12 ### 🐛 Bug Fixes @@ -233,7 +219,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.5.7-rc.2] - 2024-09-09 ### 🐛 Bug Fixes @@ -243,7 +228,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.5.7-rc.1] - 2024-09-09 ### 🚀 Features @@ -265,25 +249,21 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.5.2-3] - 2024-08-05 ### 🐛 Bug Fixes - Add os target - ## [0.5.2-2] - 2024-08-05 ### 🐛 Bug Fixes - Add os target - ## [0.5.2-1] - 2024-08-05 ### 🐛 Bug Fixes - Simplify tag creation and trigger release on push tag - ## [0.5.2] - 2024-08-05 ### 🐛 Bug Fixes @@ -301,7 +281,6 @@ All notable changes to this project will be documented in this file. - Drop windows from package list - Release tag name - Simplify tag creation and trigger release on push tag - ## [0.5.0] - 2024-07-30 ### 🚀 Features @@ -316,7 +295,6 @@ All notable changes to this project will be documented in this file. - Remove unusual reference - Add uri missing schema part - ## [0.4.1] - 2024-06-26 ### 🚀 Features @@ -344,7 +322,6 @@ All notable changes to this project will be documented in this file. ### ⚙️ Miscellaneous Tasks - Release - ## [0.3.7] - 2024-05-15 ### 🚀 Features @@ -356,5 +333,3 @@ All notable changes to this project will be documented in this file. - Clippy warning and new release flow - Clippy warning and new release flow - Clippy warning and new release flow - - diff --git a/Cargo.lock b/Cargo.lock index 664be28..a2cc3b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -582,7 +582,6 @@ dependencies = [ [[package]] name = "cranelift-assembler-x64" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cranelift-assembler-x64-meta", ] @@ -590,14 +589,20 @@ dependencies = [ [[package]] name = "cranelift-assembler-x64-meta" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" [[package]] name = "cranelift-bforest" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.118.0", +] + +[[package]] +name = "cranelift-bitset" +version = "0.118.0" +dependencies = [ + "serde", + "serde_derive", ] [[package]] @@ -612,16 +617,15 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "bumpalo", "cranelift-assembler-x64", "cranelift-bforest", - "cranelift-bitset", + "cranelift-bitset 0.118.0", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-control", - "cranelift-entity", + "cranelift-entity 0.118.0", "cranelift-isle", "gimli", "hashbrown", @@ -637,7 +641,6 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cranelift-assembler-x64", "cranelift-codegen-shared", @@ -647,22 +650,29 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" [[package]] name = "cranelift-control" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "arbitrary", ] +[[package]] +name = "cranelift-entity" +version = "0.118.0" +dependencies = [ + "cranelift-bitset 0.118.0", + "serde", + "serde_derive", +] + [[package]] name = "cranelift-entity" version = "0.118.0" source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.118.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", "serde", "serde_derive", ] @@ -670,7 +680,6 @@ dependencies = [ [[package]] name = "cranelift-frontend" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cranelift-codegen", "log", @@ -681,12 +690,10 @@ dependencies = [ [[package]] name = "cranelift-isle" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" [[package]] name = "cranelift-native" version = "0.118.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cranelift-codegen", "libc", @@ -774,7 +781,7 @@ dependencies = [ [[package]] name = "dictionary" -version = "0.11.8" +version = "0.11.9" dependencies = [ "async-trait", "reactor", @@ -948,7 +955,7 @@ dependencies = [ [[package]] name = "fastedge-run" -version = "0.11.8" +version = "0.11.9" dependencies = [ "anyhow", "async-trait", @@ -1522,7 +1529,7 @@ dependencies = [ [[package]] name = "http-backend" -version = "0.11.8" +version = "0.11.9" dependencies = [ "anyhow", "claims", @@ -1565,7 +1572,7 @@ dependencies = [ [[package]] name = "http-service" -version = "0.11.8" +version = "0.11.9" dependencies = [ "anyhow", "async-trait", @@ -1956,7 +1963,7 @@ dependencies = [ [[package]] name = "key-value-store" -version = "0.11.8" +version = "0.11.9" dependencies = [ "async-trait", "reactor", @@ -2638,9 +2645,8 @@ dependencies = [ [[package]] name = "pulley-interpreter" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ - "cranelift-bitset", + "cranelift-bitset 0.118.0", "log", "wasmtime-math", ] @@ -2796,7 +2802,7 @@ dependencies = [ [[package]] name = "reactor" -version = "0.11.8" +version = "0.11.9" dependencies = [ "wasmtime", ] @@ -2907,7 +2913,7 @@ dependencies = [ [[package]] name = "runtime" -version = "0.11.8" +version = "0.11.9" dependencies = [ "anyhow", "async-trait", @@ -2930,7 +2936,7 @@ dependencies = [ "tracing", "wasi-common", "wasmtime", - "wasmtime-environ", + "wasmtime-environ 31.0.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", "wasmtime-wasi", "wasmtime-wasi-http", "wasmtime-wasi-nn", @@ -3088,7 +3094,7 @@ dependencies = [ [[package]] name = "secret" -version = "0.11.8" +version = "0.11.9" dependencies = [ "anyhow", "reactor", @@ -3913,7 +3919,7 @@ dependencies = [ "thiserror 1.0.69", "tracing", "wasmtime", - "wiggle", + "wiggle 31.0.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", "windows-sys 0.59.0", ] @@ -4046,7 +4052,6 @@ dependencies = [ [[package]] name = "wasmtime" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "addr2line", "anyhow", @@ -4088,7 +4093,7 @@ dependencies = [ "wasmtime-component-macro", "wasmtime-component-util", "wasmtime-cranelift", - "wasmtime-environ", + "wasmtime-environ 31.0.0", "wasmtime-fiber", "wasmtime-jit-debug", "wasmtime-jit-icache-coherence", @@ -4103,7 +4108,6 @@ dependencies = [ [[package]] name = "wasmtime-asm-macros" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cfg-if", ] @@ -4111,7 +4115,6 @@ dependencies = [ [[package]] name = "wasmtime-cache" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "base64", @@ -4130,7 +4133,6 @@ dependencies = [ [[package]] name = "wasmtime-component-macro" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "proc-macro2", @@ -4144,18 +4146,16 @@ dependencies = [ [[package]] name = "wasmtime-component-util" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" [[package]] name = "wasmtime-cranelift" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "cfg-if", "cranelift-codegen", "cranelift-control", - "cranelift-entity", + "cranelift-entity 0.118.0", "cranelift-frontend", "cranelift-native", "gimli", @@ -4167,19 +4167,18 @@ dependencies = [ "target-lexicon", "thiserror 1.0.69", "wasmparser 0.226.0", - "wasmtime-environ", + "wasmtime-environ 31.0.0", "wasmtime-versioned-export-macros", ] [[package]] name = "wasmtime-environ" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "cpp_demangle", - "cranelift-bitset", - "cranelift-entity", + "cranelift-bitset 0.118.0", + "cranelift-entity 0.118.0", "gimli", "indexmap", "log", @@ -4198,9 +4197,28 @@ dependencies = [ ] [[package]] -name = "wasmtime-fiber" +name = "wasmtime-environ" version = "31.0.0" source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" +dependencies = [ + "anyhow", + "cranelift-bitset 0.118.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", + "cranelift-entity 0.118.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", + "gimli", + "indexmap", + "log", + "object", + "postcard", + "serde", + "serde_derive", + "smallvec", + "target-lexicon", + "wasmparser 0.226.0", +] + +[[package]] +name = "wasmtime-fiber" +version = "31.0.0" dependencies = [ "anyhow", "cc", @@ -4214,7 +4232,6 @@ dependencies = [ [[package]] name = "wasmtime-jit-debug" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "cc", "object", @@ -4225,7 +4242,6 @@ dependencies = [ [[package]] name = "wasmtime-jit-icache-coherence" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "cfg-if", @@ -4236,7 +4252,6 @@ dependencies = [ [[package]] name = "wasmtime-math" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "libm", ] @@ -4244,12 +4259,10 @@ dependencies = [ [[package]] name = "wasmtime-slab" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" [[package]] name = "wasmtime-versioned-export-macros" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "proc-macro2", "quote", @@ -4259,7 +4272,6 @@ dependencies = [ [[package]] name = "wasmtime-wasi" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "async-trait", @@ -4282,7 +4294,7 @@ dependencies = [ "url", "wasmtime", "wasmtime-wasi-io", - "wiggle", + "wiggle 31.0.0", "windows-sys 0.59.0", ] @@ -4311,7 +4323,6 @@ dependencies = [ [[package]] name = "wasmtime-wasi-io" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "async-trait", @@ -4323,7 +4334,6 @@ dependencies = [ [[package]] name = "wasmtime-wasi-nn" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "candle-core", @@ -4334,14 +4344,13 @@ dependencies = [ "tracing", "walkdir", "wasmtime", - "wiggle", + "wiggle 31.0.0", "windows 0.52.0", ] [[package]] name = "wasmtime-winch" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "cranelift-codegen", @@ -4350,14 +4359,13 @@ dependencies = [ "target-lexicon", "wasmparser 0.226.0", "wasmtime-cranelift", - "wasmtime-environ", + "wasmtime-environ 31.0.0", "winch-codegen", ] [[package]] name = "wasmtime-wit-bindgen" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "heck", @@ -4405,6 +4413,19 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "wiggle" +version = "31.0.0" +dependencies = [ + "anyhow", + "async-trait", + "bitflags 2.9.0", + "thiserror 1.0.69", + "tracing", + "wasmtime", + "wiggle-macro 31.0.0", +] + [[package]] name = "wiggle" version = "31.0.0" @@ -4416,7 +4437,20 @@ dependencies = [ "thiserror 1.0.69", "tracing", "wasmtime", - "wiggle-macro", + "wiggle-macro 31.0.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", +] + +[[package]] +name = "wiggle-generate" +version = "31.0.0" +dependencies = [ + "anyhow", + "heck", + "proc-macro2", + "quote", + "shellexpand", + "syn", + "witx", ] [[package]] @@ -4433,6 +4467,16 @@ dependencies = [ "witx", ] +[[package]] +name = "wiggle-macro" +version = "31.0.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wiggle-generate 31.0.0", +] + [[package]] name = "wiggle-macro" version = "31.0.0" @@ -4441,7 +4485,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wiggle-generate", + "wiggle-generate 31.0.0 (git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0)", ] [[package]] @@ -4478,7 +4522,6 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" version = "31.0.0" -source = "git+https://github.com/G-Core/wasmtime.git?branch=release-31.0.0#d7dd58b6ca6fb9fd82aa9f3010515f84b69f9f82" dependencies = [ "anyhow", "cranelift-codegen", @@ -4489,7 +4532,7 @@ dependencies = [ "thiserror 1.0.69", "wasmparser 0.226.0", "wasmtime-cranelift", - "wasmtime-environ", + "wasmtime-environ 31.0.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1b5b757..9bf29b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["crates/*"] resolver = "2" [workspace.package] -version = "0.11.8" +version = "0.11.9" edition = "2021" publish = false authors = ["FastEdge Development Team"] diff --git a/crates/http-backend/src/lib.rs b/crates/http-backend/src/lib.rs index 1c4b38c..bfb3618 100644 --- a/crates/http-backend/src/lib.rs +++ b/crates/http-backend/src/lib.rs @@ -53,7 +53,7 @@ pub struct Backend { propagate_headers: HeaderMap, propagate_header_names: HeaderNameList, max_sub_requests: usize, - strategy: BackendStrategy, + pub strategy: BackendStrategy, } pub struct Builder { diff --git a/crates/http-service/src/state.rs b/crates/http-service/src/state.rs index 063914a..090d7d5 100644 --- a/crates/http-service/src/state.rs +++ b/crates/http-service/src/state.rs @@ -17,72 +17,80 @@ pub struct HttpState { impl BackendRequest for HttpState { #[instrument(skip(self), ret, err)] - fn backend_request(&mut self, mut head: Parts) -> anyhow::Result<(String, Parts)> { - let original_url = head.uri; - tracing::trace!("send request original url: {:?}", original_url); - let original_host = original_url.authority().map(|a| { - match (original_url.scheme_str(), a.port().map(|p| p.as_u16())) { - (None, Some(80)) - | (Some("http"), Some(80)) - | (Some("https"), Some(443)) - | (_, None) => a.host().to_string(), - (_, Some(port)) => format!("{}:{}", a.host(), port), + fn backend_request(&mut self, mut head: Parts) -> anyhow::Result { + match self.http_backend.strategy { + http_backend::BackendStrategy::Direct => { + tracing::trace!("direct send request original url: {:?}", head.uri); + Ok(head) } - }); - let original_host = original_host - .or_else(|| { - head.headers.iter().find_map(|(k, v)| { - if k.as_str().eq_ignore_ascii_case("host") { - v.to_str().ok().map(|c| c.to_string()) - } else { - None + http_backend::BackendStrategy::FastEdge => { + let original_url = head.uri; + tracing::trace!("backend send request original url: {:?}", original_url); + let original_host = original_url.authority().map(|a| { + match (original_url.scheme_str(), a.port().map(|p| p.as_u16())) { + (None, Some(80)) + | (Some("http"), Some(80)) + | (Some("https"), Some(443)) + | (_, None) => a.host().to_string(), + (_, Some(port)) => format!("{}:{}", a.host(), port), } - }) - }) - .unwrap_or_default(); + }); + let original_host = original_host + .or_else(|| { + head.headers.iter().find_map(|(k, v)| { + if k.as_str().eq_ignore_ascii_case("host") { + v.to_str().ok().map(|c| c.to_string()) + } else { + None + } + }) + }) + .unwrap_or_default(); - static FILTER_HEADERS: [HeaderName; 6] = [ - header::HOST, - header::CONTENT_LENGTH, - header::TRANSFER_ENCODING, - header::UPGRADE, - HeaderName::from_static("fastedge-hostname"), - HeaderName::from_static("fastedge-scheme"), - ]; + static FILTER_HEADERS: [HeaderName; 6] = [ + header::HOST, + header::CONTENT_LENGTH, + header::TRANSFER_ENCODING, + header::UPGRADE, + HeaderName::from_static("fastedge-hostname"), + HeaderName::from_static("fastedge-scheme"), + ]; - // filter headers - let mut headers = head - .headers - .into_iter() - .filter_map(|(k, v)| k.map(|k| (k, v))) - .filter(|(k, _)| { - !FILTER_HEADERS.contains(k) && !self.propagate_header_names.contains(k) - }) - .collect::(); + // filter headers + let mut headers = head + .headers + .into_iter() + .filter_map(|(k, v)| k.map(|k| (k, v))) + .filter(|(k, _)| { + !FILTER_HEADERS.contains(k) && !self.propagate_header_names.contains(k) + }) + .collect::(); - headers.insert( - HeaderName::from_static("fastedge-hostname"), - original_host.parse()?, - ); - headers.insert( - HeaderName::from_static("fastedge-scheme"), - original_url.scheme_str().unwrap_or("http").parse()?, - ); + headers.insert( + HeaderName::from_static("fastedge-hostname"), + original_host.parse()?, + ); + headers.insert( + HeaderName::from_static("fastedge-scheme"), + original_url.scheme_str().unwrap_or("http").parse()?, + ); - headers.extend(self.propagate_headers.clone()); + headers.extend(self.propagate_headers.clone()); - let authority = self - .http_backend - .uri() - .authority() - .map(|a| a.as_str().to_string()) - .unwrap_or("localhost:10080".to_string()); - let uri = canonical_url(&original_url, &authority, self.uri.path())?; + let authority = self + .http_backend + .uri() + .authority() + .map(|a| a.as_str().to_string()) + .unwrap_or("localhost:10080".to_string()); + let uri = canonical_url(&original_url, &authority, self.uri.path())?; - head.uri = uri; - head.headers = headers; + head.uri = uri; + head.headers = headers; - Ok((authority, head)) + Ok(head) + } + } } } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index da8e524..d75312e 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -93,7 +93,7 @@ pub struct Data { } pub trait BackendRequest { - fn backend_request(&mut self, head: Parts) -> anyhow::Result<(String, Parts)>; + fn backend_request(&mut self, head: Parts) -> anyhow::Result; } impl AsRef for Data { @@ -128,7 +128,7 @@ impl WasiHttpView for Data { Self: Sized, { let (head, body) = request.into_parts(); - let (_, head) = self.inner.backend_request(head).map_err(|e| { + let head = self.inner.backend_request(head).map_err(|e| { tracing::warn!(cause=?e, "backend request"); ErrorCode::InternalError(Some(e.to_string())) })?; @@ -413,7 +413,7 @@ pub trait Router: Send + Sync { ) -> impl std::future::Future> + Send; } -pub fn componentize_if_necessary(buffer: &[u8]) -> anyhow::Result> { +pub fn componentize_if_necessary<'a>(buffer: &'a [u8]) -> anyhow::Result> { for payload in Parser::new(0).parse_all(buffer) { match payload { Ok(Payload::Version { encoding, .. }) => {