mirror of
https://github.com/faas-rs/faasd-in-rust.git
synced 2025-06-08 07:55:04 +00:00
feat(awc): introduce awc crate to match actix-web streaming requests (#94)
* feat: introduce awc crate to match actix-web streaming requests * fix(ci): fix the integration_tests mod --------- Co-authored-by: Samuka007 <dailvchen@dragonos.org>
This commit is contained in:
parent
702e6a8596
commit
ed6741cd8a
559
Cargo.lock
generated
559
Cargo.lock
generated
@ -49,7 +49,7 @@ dependencies = [
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rand",
|
||||
"rand 0.8.5",
|
||||
"sha1",
|
||||
"smallvec",
|
||||
"tokio",
|
||||
@ -121,6 +121,25 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "actix-tls"
|
||||
version = "3.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac453898d866cdbecdbc2334fe1738c747b4eba14a677261f2b768ba05329389"
|
||||
dependencies = [
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-utils",
|
||||
"futures-core",
|
||||
"http 0.2.12",
|
||||
"http 1.3.1",
|
||||
"impl-more",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "actix-utils"
|
||||
version = "3.0.1"
|
||||
@ -359,6 +378,39 @@ version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "awc"
|
||||
version = "3.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caa7cbf905267e0e80a33142717a85e334e73d878be234c62ff116cf48731ddc"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-http",
|
||||
"actix-rt",
|
||||
"actix-service",
|
||||
"actix-tls",
|
||||
"actix-utils",
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"cfg-if",
|
||||
"cookie",
|
||||
"derive_more 2.0.1",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2 0.3.26",
|
||||
"http 0.2.12",
|
||||
"itoa",
|
||||
"log",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rand 0.9.1",
|
||||
"serde 1.0.217",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum"
|
||||
version = "0.7.9"
|
||||
@ -369,7 +421,7 @@ dependencies = [
|
||||
"axum-core",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"itoa",
|
||||
@ -380,7 +432,7 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"serde 1.0.217",
|
||||
"sync_wrapper 1.0.2",
|
||||
"sync_wrapper",
|
||||
"tower 0.5.2",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
@ -395,13 +447,13 @@ dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"sync_wrapper 1.0.2",
|
||||
"sync_wrapper",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
@ -418,7 +470,7 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -427,12 +479,6 @@ version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
@ -519,12 +565,6 @@ dependencies = [
|
||||
"alloc-stdlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
@ -641,22 +681,6 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
@ -974,21 +998,6 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
@ -1117,7 +1126,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.13.3+wasi-0.2.2",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1168,7 +1177,7 @@ dependencies = [
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"indexmap 2.7.1",
|
||||
"slab",
|
||||
"tokio",
|
||||
@ -1233,9 +1242,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.2.0"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
|
||||
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@ -1260,7 +1269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1271,7 +1280,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"pin-project-lite",
|
||||
]
|
||||
@ -1328,7 +1337,7 @@ dependencies = [
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"h2 0.4.7",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
@ -1352,19 +1361,6 @@ dependencies = [
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hyper 0.14.32",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-util"
|
||||
version = "0.1.10"
|
||||
@ -1374,7 +1370,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"hyper 1.5.2",
|
||||
"pin-project-lite",
|
||||
@ -1568,12 +1564,6 @@ dependencies = [
|
||||
"hashbrown 0.15.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.15"
|
||||
@ -1639,16 +1629,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "language-tags"
|
||||
version = "0.3.2"
|
||||
@ -1813,23 +1793,6 @@ dependencies = [
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netns-rs"
|
||||
version = "0.1.0"
|
||||
@ -1918,50 +1881,6 @@ version = "1.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e14130c6a98cd258fdcb0fb6d744152343ff729cbfcb28c656a9d12b999fbcd"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bb61ea9811cc39e3c2069f40b8b8e2e70d8569b361f879786cc7ed48b777cdd"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.3"
|
||||
@ -1982,7 +1901,7 @@ dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2242,6 +2161,7 @@ dependencies = [
|
||||
"actix-web",
|
||||
"actix-web-httpauth",
|
||||
"async-trait",
|
||||
"awc",
|
||||
"base64 0.13.1",
|
||||
"bollard",
|
||||
"cni",
|
||||
@ -2249,13 +2169,12 @@ dependencies = [
|
||||
"derive_more 2.0.1",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"hyper 0.14.32",
|
||||
"http 1.3.1",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"my-workspace-hack",
|
||||
"prometheus",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"serde 1.0.217",
|
||||
"serde_json",
|
||||
"service",
|
||||
@ -2284,8 +2203,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_chacha 0.3.1",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
||||
dependencies = [
|
||||
"rand_chacha 0.9.0",
|
||||
"rand_core 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2295,7 +2224,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2307,6 +2246,15 @@ dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.8"
|
||||
@ -2351,46 +2299,6 @@ version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2 0.3.26",
|
||||
"http 0.2.12",
|
||||
"http-body 0.4.6",
|
||||
"hyper 0.14.32",
|
||||
"hyper-tls",
|
||||
"ipnet",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls-pemfile",
|
||||
"serde 1.0.217",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper 0.1.2",
|
||||
"system-configuration",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-ini"
|
||||
version = "0.13.0"
|
||||
@ -2425,15 +2333,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pemfile"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.19"
|
||||
@ -2446,44 +2345,12 @@ version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "2.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
|
||||
dependencies = [
|
||||
"bitflags 2.8.0",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "2.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.25"
|
||||
@ -2722,12 +2589,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sync_wrapper"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
|
||||
|
||||
[[package]]
|
||||
name = "sync_wrapper"
|
||||
version = "1.0.2"
|
||||
@ -2745,27 +2606,6 @@ dependencies = [
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"core-foundation",
|
||||
"system-configuration-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration-sys"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.15.0"
|
||||
@ -2899,16 +2739,6 @@ dependencies = [
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.17"
|
||||
@ -2954,7 +2784,7 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"h2 0.4.7",
|
||||
"http 1.2.0",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"hyper 1.5.2",
|
||||
@ -2997,7 +2827,7 @@ dependencies = [
|
||||
"indexmap 1.9.3",
|
||||
"pin-project",
|
||||
"pin-project-lite",
|
||||
"rand",
|
||||
"rand 0.8.5",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
@ -3015,7 +2845,7 @@ dependencies = [
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"pin-project-lite",
|
||||
"sync_wrapper 1.0.2",
|
||||
"sync_wrapper",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
@ -3138,12 +2968,6 @@ dependencies = [
|
||||
"getrandom 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
@ -3174,87 +2998,6 @@ dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@ -3286,22 +3029,13 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3310,22 +3044,7 @@ version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3334,46 +3053,28 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.6",
|
||||
"windows_aarch64_msvc 0.52.6",
|
||||
"windows_i686_gnu 0.52.6",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc 0.52.6",
|
||||
"windows_x86_64_gnu 0.52.6",
|
||||
"windows_x86_64_gnullvm 0.52.6",
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
@ -3386,64 +3087,30 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.50.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.33.0"
|
||||
|
@ -11,6 +11,8 @@ mod integration_tests {
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
use serde_json::json;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[actix_web::test]
|
||||
#[ignore]
|
||||
@ -37,7 +39,7 @@ mod integration_tests {
|
||||
.uri("/function/test-no-found-function")
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
|
||||
let response_body = test::read_body(resp).await;
|
||||
let response_str = std::str::from_utf8(&response_body).unwrap();
|
||||
assert!(response_str.contains("Failed to get function"));
|
||||
@ -76,6 +78,7 @@ mod integration_tests {
|
||||
log::info!("{}", response_str);
|
||||
assert!(response_str.contains("Function test-function deployment initiated successfully."));
|
||||
|
||||
sleep(Duration::from_secs(2));
|
||||
// test proxy in namespace 'default'
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/function/test-function")
|
||||
|
@ -14,10 +14,9 @@ uuid = { version = "1.8.0", features = ["v4"] }
|
||||
actix-web-httpauth = "0.6"
|
||||
config = "0.11"
|
||||
thiserror = "1.0"
|
||||
reqwest = "0.11"
|
||||
awc = "3.6.0"
|
||||
prometheus = "0.13"
|
||||
tempfile = "3.2"
|
||||
hyper = "0.14"
|
||||
tower = "0.4"
|
||||
regex = "1"
|
||||
futures = "0.3"
|
||||
@ -33,3 +32,4 @@ my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }
|
||||
url = "2.4"
|
||||
derive_more = { version = "2", features = ["full"] }
|
||||
tonic = "0.12"
|
||||
http = "1.3.1"
|
||||
|
@ -26,8 +26,10 @@ pub async fn delete_handler(info: web::Json<DeleteContainerInfo>) -> impl Respon
|
||||
Ok(function) => function,
|
||||
Err(e) => {
|
||||
log::error!("Failed to get function: {}", e);
|
||||
return HttpResponse::NotFound()
|
||||
.body(format!("Function '{}' not found ", function_name));
|
||||
return HttpResponse::NotFound().body(format!(
|
||||
"Function '{}' not found in namespace '{}'",
|
||||
function_name, namespace
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,7 @@ pub async fn deploy_handler(info: web::Json<DeployFunctionInfo>) -> impl Respond
|
||||
|
||||
match deploy(&function_name, &image, &namespace).await {
|
||||
Ok(()) => HttpResponse::Accepted().body(format!(
|
||||
"Function {} deployment initiated successfully .",
|
||||
"Function {} deployment initiated successfully.",
|
||||
function_name
|
||||
)),
|
||||
Err(e) => HttpResponse::BadRequest().body(format!(
|
||||
|
@ -1,41 +1,40 @@
|
||||
use actix_web::{Error, HttpRequest, web};
|
||||
use futures::StreamExt;
|
||||
use reqwest::{Client, RequestBuilder};
|
||||
use actix_web::{HttpRequest, web};
|
||||
|
||||
use awc::http::Uri;
|
||||
use url::Url;
|
||||
//根据URL和原始请求来构建转发请求,并对请求头进行处理
|
||||
pub async fn build_proxy_request(
|
||||
pub fn create_proxy_request(
|
||||
req: &HttpRequest,
|
||||
base_url: &Url,
|
||||
proxy_client: &Client,
|
||||
mut payload: web::Payload,
|
||||
) -> Result<RequestBuilder, Error> {
|
||||
payload: web::Payload,
|
||||
) -> awc::SendClientRequest {
|
||||
let proxy_client = awc::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(10))
|
||||
.finish();
|
||||
let origin_url = base_url.join(req.uri().path()).unwrap();
|
||||
let remaining_segments = origin_url.path_segments().unwrap().skip(2);
|
||||
let rest_path = remaining_segments.collect::<Vec<_>>().join("/");
|
||||
let url = base_url.join(&rest_path).unwrap();
|
||||
let mut proxy_req = proxy_client
|
||||
.request(req.method().clone(), url)
|
||||
.headers(req.headers().clone().into());
|
||||
|
||||
let uri = url.as_str().parse::<Uri>().unwrap();
|
||||
|
||||
let mut proxy_req = proxy_client.request(req.method().clone(), uri);
|
||||
|
||||
for header in req.headers() {
|
||||
proxy_req = proxy_req.insert_header(header);
|
||||
}
|
||||
|
||||
if req.headers().get("X-Forwarded-Host").is_none() {
|
||||
if let Some(host) = req.headers().get("Host") {
|
||||
proxy_req = proxy_req.header("X-Forwarded-Host", host);
|
||||
proxy_req = proxy_req.insert_header(("X-Forwarded-Host", host));
|
||||
}
|
||||
}
|
||||
|
||||
if req.headers().get("X-Forwarded-For").is_none() {
|
||||
if let Some(remote_addr) = req.peer_addr() {
|
||||
proxy_req = proxy_req.header("X-Forwarded-For", remote_addr.to_string());
|
||||
proxy_req = proxy_req.insert_header(("X-Forwarded-For", remote_addr.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
let mut body = web::BytesMut::new();
|
||||
while let Some(chunk) = payload.next().await {
|
||||
let chunk = chunk?;
|
||||
body.extend_from_slice(&chunk);
|
||||
}
|
||||
let body_bytes = body.freeze();
|
||||
let proxy_req = proxy_req.body(body_bytes);
|
||||
|
||||
Ok(proxy_req)
|
||||
proxy_req.send_stream(payload)
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use reqwest::{Client, redirect};
|
||||
|
||||
use crate::types::config::FaaSConfig;
|
||||
|
||||
//构建client
|
||||
pub async fn new_proxy_client_from_config(config: &FaaSConfig) -> Client {
|
||||
new_proxy_client(
|
||||
config.get_read_timeout(),
|
||||
/*config.get_max_idle_conns(),*/ config.get_max_idle_conns_per_host(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
//根据FaasConfig参数来设置Client
|
||||
pub async fn new_proxy_client(
|
||||
timeout: Duration,
|
||||
//max_idle_conns: usize,
|
||||
max_idle_conns_per_host: usize,
|
||||
) -> Client {
|
||||
Client::builder()
|
||||
.connect_timeout(timeout)
|
||||
.timeout(timeout)
|
||||
.pool_max_idle_per_host(max_idle_conns_per_host)
|
||||
.pool_idle_timeout(Duration::from_millis(120))
|
||||
.tcp_keepalive(120 * Duration::from_secs(1))
|
||||
.redirect(redirect::Policy::none())
|
||||
.tcp_nodelay(true)
|
||||
.build()
|
||||
.expect("Failed to create client")
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
pub mod builder;
|
||||
pub mod client;
|
||||
pub mod proxy_handler;
|
||||
mod proxy_handler_test;
|
||||
|
@ -1,9 +1,8 @@
|
||||
use crate::handlers::invoke_resolver::InvokeResolver;
|
||||
use crate::proxy::builder::build_proxy_request;
|
||||
use crate::proxy::client::new_proxy_client_from_config;
|
||||
use crate::types::config::FaaSConfig;
|
||||
use crate::proxy::builder::create_proxy_request;
|
||||
|
||||
use actix_web::{
|
||||
Error, HttpRequest, HttpResponse,
|
||||
HttpRequest, HttpResponse,
|
||||
error::{ErrorBadRequest, ErrorInternalServerError, ErrorMethodNotAllowed},
|
||||
http::Method,
|
||||
web,
|
||||
@ -11,13 +10,9 @@ use actix_web::{
|
||||
|
||||
// 主要参考源码的响应设置
|
||||
pub async fn proxy_handler(
|
||||
config: web::Data<FaaSConfig>,
|
||||
req: HttpRequest,
|
||||
payload: web::Payload,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let proxy_client = new_proxy_client_from_config(config.as_ref()).await;
|
||||
log::info!("proxy_client : {:?}", proxy_client);
|
||||
|
||||
) -> actix_web::Result<HttpResponse> {
|
||||
match *req.method() {
|
||||
Method::POST
|
||||
| Method::PUT
|
||||
@ -25,8 +20,8 @@ pub async fn proxy_handler(
|
||||
| Method::GET
|
||||
| Method::PATCH
|
||||
| Method::HEAD
|
||||
| Method::OPTIONS => proxy_request(&req, payload, &proxy_client).await,
|
||||
_ => Err(ErrorMethodNotAllowed("method not allowed")),
|
||||
| Method::OPTIONS => proxy_request(&req, payload).await,
|
||||
_ => Err(ErrorMethodNotAllowed("Method not allowed")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,30 +29,31 @@ pub async fn proxy_handler(
|
||||
async fn proxy_request(
|
||||
req: &HttpRequest,
|
||||
payload: web::Payload,
|
||||
proxy_client: &reqwest::Client,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
) -> actix_web::Result<HttpResponse> {
|
||||
let function_name = req.match_info().get("name").unwrap_or("");
|
||||
if function_name.is_empty() {
|
||||
return Err(ErrorBadRequest("function name is required"));
|
||||
return Err(ErrorBadRequest("Function name is required"));
|
||||
}
|
||||
|
||||
let function_addr = InvokeResolver::resolve_function_url(function_name).await?;
|
||||
|
||||
let proxy_req = build_proxy_request(req, &function_addr, proxy_client, payload).await?;
|
||||
let proxy_req = create_proxy_request(req, &function_addr, payload);
|
||||
|
||||
match proxy_req.send().await {
|
||||
Ok(resp) => {
|
||||
let status = resp.status();
|
||||
let mut client_resp = HttpResponse::build(status);
|
||||
|
||||
for (name, value) in resp.headers().iter() {
|
||||
client_resp.insert_header((name.clone(), value.clone()));
|
||||
}
|
||||
|
||||
let body = resp.bytes().await.unwrap();
|
||||
|
||||
Ok(client_resp.body(body))
|
||||
// Handle the error conversion explicitly
|
||||
let proxy_resp = match proxy_req.await {
|
||||
Ok(resp) => resp,
|
||||
Err(e) => {
|
||||
log::error!("Proxy request failed: {}", e);
|
||||
return Err(ErrorInternalServerError(format!(
|
||||
"Proxy request failed: {}",
|
||||
e
|
||||
)));
|
||||
}
|
||||
Err(e) => Err(ErrorInternalServerError(e)),
|
||||
}
|
||||
};
|
||||
|
||||
// Now create an HttpResponse from the proxy response
|
||||
let mut client_resp = HttpResponse::build(proxy_resp.status());
|
||||
|
||||
// Stream the response body
|
||||
Ok(client_resp.streaming(proxy_resp))
|
||||
}
|
||||
|
127
crates/provider/src/proxy/proxy_handler_test.rs
Normal file
127
crates/provider/src/proxy/proxy_handler_test.rs
Normal file
@ -0,0 +1,127 @@
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::proxy::proxy_handler::proxy_handler;
|
||||
use actix_web::{
|
||||
App, HttpRequest, HttpResponse, Responder, http,
|
||||
test::{self},
|
||||
web::{self, Bytes},
|
||||
};
|
||||
|
||||
#[actix_web::test]
|
||||
#[ignore]
|
||||
async fn test_proxy_handler_success() {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_path_parsing() {
|
||||
let test_cases = vec![
|
||||
("simple_name_match", "/function/echo", "echo", "", 200),
|
||||
(
|
||||
"simple_name_match",
|
||||
"/function/echo.faasd-in-rs-fn",
|
||||
"echo.faasd-in-rs-fn",
|
||||
"",
|
||||
200,
|
||||
),
|
||||
(
|
||||
"simple_name_match_with_trailing_slash",
|
||||
"/function/echo/",
|
||||
"echo",
|
||||
"",
|
||||
200,
|
||||
),
|
||||
(
|
||||
"name_match_with_additional_path_values",
|
||||
"/function/echo/subPath/extras",
|
||||
"echo",
|
||||
"subPath/extras",
|
||||
200,
|
||||
),
|
||||
(
|
||||
"name_match_with_additional_path_values_and_querystring",
|
||||
"/function/echo/subPath/extras?query=true",
|
||||
"echo",
|
||||
"subPath/extras",
|
||||
200,
|
||||
),
|
||||
("not_found_if_no_name", "/function/", "", "", 404),
|
||||
];
|
||||
|
||||
let app = test::init_service(
|
||||
App::new()
|
||||
.route("/function/{name}", web::get().to(var_handler))
|
||||
.route("/function/{name}/", web::get().to(var_handler))
|
||||
.route("/function/{name}/{params:.*}", web::get().to(var_handler)),
|
||||
)
|
||||
.await;
|
||||
|
||||
for (name, path, function_name, extra_path, status_code) in test_cases {
|
||||
let req = test::TestRequest::get().uri(path).to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
|
||||
assert_eq!(resp.status().as_u16(), status_code, "Test case: {}", name);
|
||||
|
||||
if status_code == 200 {
|
||||
let body = test::read_body(resp).await;
|
||||
let expected_body = format!("name: {} params: {}", function_name, extra_path);
|
||||
assert_eq!(body, expected_body.as_bytes(), "Test case: {}", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_handler_func_invalid_method() {
|
||||
let app = test::init_service(
|
||||
App::new().route("/function/{name}{path:/?.*}", web::to(proxy_handler)),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::with_uri("/function/test-service/path")
|
||||
.method(http::Method::from_bytes(b"INVALID").unwrap())
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
assert_eq!(resp.status(), http::StatusCode::METHOD_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_handler_func_empty_function_nam() {
|
||||
let app = test::init_service(
|
||||
App::new().route("/function{name:/?}{path:/?.*}", web::to(proxy_handler)),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/function")
|
||||
.insert_header((http::header::CONTENT_TYPE, "application/json"))
|
||||
.set_payload(Bytes::from_static(b"{\"key\":\"value\"}"))
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
assert_eq!(resp.status(), http::StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_handler_func_empty_function_name() {
|
||||
let app = test::init_service(
|
||||
App::new().route("/function{name:/?}{path:/?.*}", web::to(proxy_handler)),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/function")
|
||||
.insert_header((http::header::CONTENT_TYPE, "application/json"))
|
||||
.set_payload(Bytes::from_static(b"{\"key\":\"value\"}"))
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
assert_eq!(resp.status(), http::StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
async fn var_handler(req: HttpRequest) -> impl Responder {
|
||||
let vars = req.match_info();
|
||||
HttpResponse::Ok().body(format!(
|
||||
"name: {} params: {}",
|
||||
vars.get("name").unwrap_or(""),
|
||||
vars.get("params").unwrap_or("")
|
||||
))
|
||||
}
|
||||
}
|
@ -111,7 +111,8 @@ paths:
|
||||
description: Method Not Allowed
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
||||
'503':
|
||||
description: Error Service Unavailable
|
||||
components:
|
||||
schemas:
|
||||
FunctionDeployment:
|
||||
|
Loading…
x
Reference in New Issue
Block a user