diff --git a/frameworks/sark-gateway/compose.gateway-h3.yml b/frameworks/sark-gateway/compose.gateway-h3.yml index ec9355518..70d937d4b 100644 --- a/frameworks/sark-gateway/compose.gateway-h3.yml +++ b/frameworks/sark-gateway/compose.gateway-h3.yml @@ -31,3 +31,4 @@ services: - DATABASE_URL=${DATABASE_URL} - DATABASE_MAX_CONN=${DATABASE_MAX_CONN:-32} - SARK_HTTPARENA_PER_IP_CAP=0 + - SARK_HTTPARENA_H1_ONLY=1 diff --git a/frameworks/sark-gateway/compose.gateway.yml b/frameworks/sark-gateway/compose.gateway.yml index ba5cb8b62..879e12091 100644 --- a/frameworks/sark-gateway/compose.gateway.yml +++ b/frameworks/sark-gateway/compose.gateway.yml @@ -1,3 +1,7 @@ +# The sark io_uring `server` busy-polls (Throughput profile spins while it holds +# connections), so it must NOT share cores with the yielding proxy — otherwise it +# starves nginx and the stack serves 0 RPS. Keep GATEWAY_SERVER_CPUS disjoint from +# GATEWAY_PROXY_CPUS (compose.gateway-h3.yml already does: proxy 0-1, server 2). services: proxy: build: @@ -16,7 +20,7 @@ services: context: ../sark dockerfile: Dockerfile network_mode: host - cpuset: "${GATEWAY_SERVER_CPUS:-0-2}" + cpuset: "${GATEWAY_SERVER_CPUS:-3-5}" security_opt: - seccomp:unconfined ulimits: @@ -26,8 +30,9 @@ services: hard: 1048576 environment: - SARK_HTTPARENA_BIND=0.0.0.0:8080 - - SARK_HTTPARENA_CPU_CORE=${GATEWAY_SERVER_CPU_CORE:-0} + - SARK_HTTPARENA_CPU_CORE=${GATEWAY_SERVER_CPU_CORE:-3} - SARK_HTTPARENA_CPU_COUNT=${GATEWAY_SERVER_CPU_COUNT:-3} - DATABASE_URL=${DATABASE_URL} - DATABASE_MAX_CONN=${DATABASE_MAX_CONN:-32} - SARK_HTTPARENA_PER_IP_CAP=0 + - SARK_HTTPARENA_H1_ONLY=1 diff --git a/frameworks/sark-production/compose.production-stack.yml b/frameworks/sark-production/compose.production-stack.yml index d7d80a58d..73e91a680 100644 --- a/frameworks/sark-production/compose.production-stack.yml +++ b/frameworks/sark-production/compose.production-stack.yml @@ -1,3 +1,8 @@ +# CPU layout: the sark io_uring `server` busy-polls (Throughput profile spins +# while it holds connections), so it must NOT share cores with the yielding +# edge/authsvc/cache — otherwise it starves them and the whole stack serves +# 0 RPS. `server` is pinned to GATEWAY_SERVER_CPUS (its own range); the proxy, +# auth sidecar and redis share GATEWAY_PROXY_CPUS. Keep the two ranges DISJOINT. services: edge: build: ./proxy-production @@ -20,14 +25,14 @@ services: cache: image: redis:7-alpine network_mode: host - cpuset: "${GATEWAY_SERVER_CPUS:-0-2}" + cpuset: "${GATEWAY_PROXY_CPUS:-0-2}" security_opt: - seccomp:unconfined authsvc: build: ../_shared/authsvc network_mode: host - cpuset: "${GATEWAY_SERVER_CPUS:-0-2}" + cpuset: "${GATEWAY_PROXY_CPUS:-0-2}" security_opt: - seccomp:unconfined environment: @@ -39,7 +44,7 @@ services: context: ../sark dockerfile: Dockerfile network_mode: host - cpuset: "${GATEWAY_SERVER_CPUS:-0-2}" + cpuset: "${GATEWAY_SERVER_CPUS:-3-5}" security_opt: - seccomp:unconfined ulimits: @@ -49,11 +54,12 @@ services: hard: 1048576 environment: - SARK_HTTPARENA_BIND=0.0.0.0:8080 - - SARK_HTTPARENA_CPU_CORE=${GATEWAY_SERVER_CPU_CORE:-0} + - SARK_HTTPARENA_CPU_CORE=${GATEWAY_SERVER_CPU_CORE:-3} - SARK_HTTPARENA_CPU_COUNT=${GATEWAY_SERVER_CPU_COUNT:-3} - DATABASE_URL=${DATABASE_URL} - DATABASE_MAX_CONN=${DATABASE_MAX_CONN:-128} - REDIS_URL=redis://127.0.0.1:6379 - SARK_HTTPARENA_PER_IP_CAP=0 + - SARK_HTTPARENA_H1_ONLY=1 depends_on: - cache diff --git a/frameworks/sark/Cargo.lock b/frameworks/sark/Cargo.lock index 4f6b3896c..36581c11c 100644 --- a/frameworks/sark/Cargo.lock +++ b/frameworks/sark/Cargo.lock @@ -11,6 +11,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "anyhow" version = "1.0.103" @@ -91,6 +106,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bit-vec" version = "0.9.1" @@ -115,6 +136,27 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "brotli" +version = "8.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bytes" version = "1.12.0" @@ -204,6 +246,12 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "cpufeatures" version = "0.3.0" @@ -220,6 +268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ "hybrid-array", + "rand_core", ] [[package]] @@ -237,6 +286,16 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" +[[package]] +name = "der" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "der-parser" version = "10.0.0" @@ -281,9 +340,9 @@ dependencies = [ [[package]] name = "dope" -version = "0.5.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f2af5f0b2507932706f970ded9a6c4de89431a9f855a7d61a0c7e698857781" +checksum = "99b1fe82bd8665f9b2d78a47b2c28834c9d3dbd6497575d7ebdad07de6acc35e" dependencies = [ "io-uring", "libc", @@ -293,9 +352,9 @@ dependencies = [ [[package]] name = "dope-extra" -version = "0.5.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ce0d8ae99e97adb8a9b4247d382d0726ee84c01547e2151909dd967d2ca411" +checksum = "0acda19f64a371f88a39a77b27322719008851221fd670b206544f0fe46be8c5" dependencies = [ "dope", "libc", @@ -304,9 +363,9 @@ dependencies = [ [[package]] name = "dope-gen" -version = "0.5.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8352e7b40f75f8af0e895b272048761eb16809c91f387d5d3cdac28c0b05a029" +checksum = "172c8823fb0399a240959a6707648cb73153b102cfdd3d565b6eb49dc9a777ee" dependencies = [ "proc-macro2", "quote", @@ -315,9 +374,9 @@ dependencies = [ [[package]] name = "dope-quic" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efd83eb653fea7b22da51f6db6294f3fb80071313067fb5199ba45b32110170" +checksum = "a61b598cd75cc71e9cf380dbfa88d6438bf9603acd2c50b86a27d793e25084fe" dependencies = [ "dope", "dope-gen", @@ -330,9 +389,9 @@ dependencies = [ [[package]] name = "dope-tls" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c9396db331682a3e5ef84809f1b86bf40599ba4326c47d81b2e15ff7d7fc1c7" +checksum = "46cfc0e9cac6cc1975deab97fa718cdacc9fc0a5c0f14528cd6b2cfa26859cc3" dependencies = [ "dope", "libc", @@ -441,7 +500,7 @@ dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", - "rand_core 0.10.1", + "rand_core", ] [[package]] @@ -531,11 +590,13 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "hybrid-array" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" +checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c" dependencies = [ + "ctutils", "typenum", + "zeroize", ] [[package]] @@ -550,9 +611,9 @@ dependencies = [ [[package]] name = "io-uring" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d09b98f7eace8982db770e4408e7470b028ce513ac28fecdc6bf4c30fe92b62" +checksum = "9080b15e63775b9a2ac7dca720f7050a8b955e092ea0f6020a4a80f69998cdc0" dependencies = [ "bitflags", "cfg-if", @@ -584,6 +645,26 @@ dependencies = [ "libc", ] +[[package]] +name = "keccak" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e24a010dd405bd7ed803e5253182815b41bf2e6a80cc3bfc066658e03a198aa" +dependencies = [ + "cfg-if", + "cpufeatures", +] + +[[package]] +name = "kem" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01737161ba802849cfd486b5bd209d38ba4943494c249a8126005170c7621edd" +dependencies = [ + "crypto-common", + "rand_core", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -638,6 +719,33 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "ml-kem" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e15f3e5b957493873e396a66914e83e616b6afe335cdef7efe5c6e1216aba66" +dependencies = [ + "hybrid-array", + "kem", + "module-lattice", + "pkcs8", + "rand_core", + "sha3", + "zeroize", +] + +[[package]] +name = "module-lattice" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c61b87c9683ab7cb1c6871d261ad5479b6b10ceb52c4352aaca3b5d35a8febe" +dependencies = [ + "ctutils", + "hybrid-array", + "num-traits", + "zeroize", +] + [[package]] name = "multimap" version = "0.10.1" @@ -759,6 +867,16 @@ dependencies = [ "syn", ] +[[package]] +name = "pkcs8" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -872,26 +990,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "getrandom 0.4.3", - "rand_core 0.10.1", + "rand_core", ] [[package]] name = "rand_chacha" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +checksum = "3e6af7f3e25ded52c41df4e0b1af2d047e45896c2f3281792ed68a1c243daedb" dependencies = [ "ppv-lite86", - "rand_core 0.9.5", -] - -[[package]] -name = "rand_core" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" -dependencies = [ - "getrandom 0.3.4", + "rand_core", ] [[package]] @@ -996,9 +1105,9 @@ checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "sark" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ca0d62dc00179336a99c67ba367e73df0d5e577a56f12110478697d8e9512d" +checksum = "c7196fcd46aacb13236dca521543dfb57c2f56d2c4051c85f2964046ece54fb2" dependencies = [ "dope", "dope-extra", @@ -1017,10 +1126,11 @@ dependencies = [ [[package]] name = "sark-core" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd4939154594f8aa2f44bc0460b8f4038abda3f6ac5a427f83fbe2c2521a93" +checksum = "cf083a0795bfd547429867b02ee87199488eab1f554ae33d393975fa59d262b7" dependencies = [ + "brotli", "http", "httparse", "libdeflater", @@ -1034,9 +1144,9 @@ dependencies = [ [[package]] name = "sark-gen" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea73efb9483ff8e25d560a00416a584a19bec3d999b7f87c8089e54ff5e07d8" +checksum = "96ea2a2d9138d08ac00c8920d42ee85a87c23f1364c317e17076dcf6f1ac9a56" dependencies = [ "dope", "o3", @@ -1047,9 +1157,9 @@ dependencies = [ [[package]] name = "sark-grpc" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3665a1f8ebf14b599ead1ebae3c333e00133ed22630a255f1828e171378b87c" +checksum = "9393f1a9f03f4649c9a87cdd54b34b571028418d451734e5d0a8c3d0b1ab565c" dependencies = [ "dope", "dope-extra", @@ -1064,18 +1174,18 @@ dependencies = [ [[package]] name = "sark-grpc-build" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14991dcd6c9a4f5330d8ef012f3d749cab682512647be1bb4edffa9acfd7bc9a" +checksum = "20309e9e3d9c9793baa03d5eb654fa1fac813b1f8d78dc27a079c02401932d19" dependencies = [ "prost-build", ] [[package]] name = "sark-h2" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9daff2eebc0646ec9e82752cdd4c8196f7c16a85c2bf1c360ca4a26b1317cff" +checksum = "8bdbb30c78ee58e806414e86f2b7a8bb73702323a27111d18e0381b76fb1a249" dependencies = [ "dope", "dope-extra", @@ -1089,9 +1199,9 @@ dependencies = [ [[package]] name = "sark-h3" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "108b80be29c10a88c345594513b9664e173e02f55cd28b482e3860afac7a9f57" +checksum = "c3d3eb1a264db3666f88b41c636e6fb58710024f870ee61955691bace1b57101" dependencies = [ "dope-quic", "sark", @@ -1100,9 +1210,9 @@ dependencies = [ [[package]] name = "sark-json" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3a6140ea76e6e5497d57a968a6098a0be3701e64883ed7e4eb627384dc8a2f" +checksum = "4cacf8894eab059e3d30e9926352b14f4c81852ce674f207cc132780bab9e9b3" dependencies = [ "http", "o3", @@ -1111,9 +1221,9 @@ dependencies = [ [[package]] name = "sark-ws" -version = "0.6.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebce2b50a1ff93bedc56f4a49691e818e504228db2e697f4ac3fb18205df9a65" +checksum = "b895365c8ce10f2652171c53647a2d62bd3f0283c649fe2f794dc044e013b9b3" dependencies = [ "dope", "dope-extra", @@ -1122,7 +1232,7 @@ dependencies = [ "o3", "pin-project", "rand_chacha", - "rand_core 0.9.5", + "rand_core", "sark-core", ] @@ -1192,12 +1302,24 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be176f1a57ce4e3d31c1a166222d9768de5954f811601fb7ca06fc8203905ce1" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "shin" -version = "0.3.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a10cddc4d4991f721e480d80f9825b5e1113b02750f8eaa612a23b42266ff88" +checksum = "05cab1b518ee86d87f298dc380d376159b46b0dcf5e02ab5c698410819efa9bb" dependencies = [ + "ml-kem", + "rand_core", "ring", "subtle", ] @@ -1208,6 +1330,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "spki" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "stringprep" version = "0.1.5" diff --git a/frameworks/sark/Cargo.toml b/frameworks/sark/Cargo.toml index ef7af5dff..a55867ebd 100644 --- a/frameworks/sark/Cargo.toml +++ b/frameworks/sark/Cargo.toml @@ -9,22 +9,22 @@ edition = "2024" dope = "0.5" dope-gen = "0.5" dope-extra = "0.5" -dope-tls = "0.6" -dope-quic = "0.3" +dope-tls = "0.8" +dope-quic = "0.5" o3 = "0.2" -sark = "0.6" -sark-core = "0.6" -sark-gen = "0.6" -sark-ws = "0.6" -sark-h2 = "0.6" -sark-h3 = "0.6" -sark-grpc = "0.6" -sark-grpc-build = "0.6" +sark = "0.8" +sark-core = "0.8" +sark-gen = "0.8" +sark-ws = "0.8" +sark-h2 = "0.8" +sark-h3 = "0.8" +sark-grpc = "0.8" +sark-grpc-build = "0.8" cartel-pg = "0.3" cartel-redis = "0.3" cartel-gen = "0.3" tent = "0.2" -shin = "0.3" +shin = "0.7" http = "1.4" prost = "0.14.3" pin-project = "1" diff --git a/frameworks/sark/httparena/src/lib.rs b/frameworks/sark/httparena/src/lib.rs index bd2face41..40abe3d46 100644 --- a/frameworks/sark/httparena/src/lib.rs +++ b/frameworks/sark/httparena/src/lib.rs @@ -46,7 +46,7 @@ pub mod tls { }, transport_params: Vec::new(), alpn_protocols, - ticket_secret: None, + ticket_keys: None, accept_early_data: false, } } diff --git a/frameworks/sark/httparena/src/main.rs b/frameworks/sark/httparena/src/main.rs index 2bc46d5d9..b6ab0a77a 100644 --- a/frameworks/sark/httparena/src/main.rs +++ b/frameworks/sark/httparena/src/main.rs @@ -31,7 +31,7 @@ use sark::fs::ServeDir; use sark::json::{Encode, Json, JsonDecode, JsonEncode, Writer}; use sark::request::BodyLen; use sark::timer::{DEFAULT_HEAD_TIMEOUT, SARK_TIMER_ID, TimerHost}; -use sark_core::http::compress::Gzip; +use sark_core::http::compress::{Brotli, Gzip}; use sark_core::http::{LocalFrameBytes, Response}; use sark_grpc::server::App as GrpcApp; use sark_h2::server::App as H2App; @@ -114,15 +114,15 @@ fn u64_owned(n: u64) -> Owned { body } -fn accepts_gzip(accept_encoding: &[u8]) -> bool { +fn accepts(accept_encoding: &[u8], coding: &[u8]) -> bool { accept_encoding.split(|&b| b == b',').any(|part| { - let part = part.trim_ascii(); - let coding = part + let c = part + .trim_ascii() .split(|&b| b == b';') .next() .unwrap_or(b"") .trim_ascii(); - coding.eq_ignore_ascii_case(b"gzip") + c.eq_ignore_ascii_case(coding) }) } @@ -130,11 +130,16 @@ fn respond_json(value: T, accept_encoding: &[u8]) -> Response { let body = value.encode_json(); let mut response = Response::ok(); response.content_type("application/json"); - if accepts_gzip(accept_encoding) { + if accepts(accept_encoding, b"gzip") { let compressed = Gzip::with_thread_local(|g| Shared::from(g.encode(&body).to_vec())); response.append_wire_header_static("content-encoding", "gzip"); response.append_wire_header_static("vary", "accept-encoding"); response.set_body(compressed); + } else if accepts(accept_encoding, b"br") { + let compressed = Brotli::with_thread_local(|b| Shared::from(b.encode(&body).to_vec())); + response.append_wire_header_static("content-encoding", "br"); + response.append_wire_header_static("vary", "accept-encoding"); + response.set_body(compressed); } else { response.set_body(body); } @@ -311,6 +316,7 @@ struct PipelineRequest {} #[sark_gen::handler] #[static_response] +#[skip(date, server)] fn pipeline_endpoint(_req: PipelineRequest, _state: &AppState<'_>) -> PipelineResponse { PipelineResponse { status: StatusCode::OK, @@ -814,6 +820,7 @@ struct PortArgs { json_tls_bind: SocketAddr, h2c_bind: SocketAddr, h2_bind: SocketAddr, + h1_only: bool, } struct PgArgs { @@ -908,53 +915,63 @@ fn run_thread(pg: PgArgs, ports: PortArgs, cfg: ServerCfg, ctx: launcher::Ctx) - std::ptr::NonNull::from(handler.date_stamp()) }; - let mut json_tls = { - let driver = exec.driver_mut(); - Listener::<2, _, TlsProd>::open_in( - tls_app::new::(&()), - listener_cfg(ports.json_tls_bind, cfg.max_conn), - driver, - )? - }; - json_tls.set_cfg(Endpoint::Server(Box::new(httparena_sark::tls::config( - vec![b"http/1.1".to_vec()], - )))); - let tls_stamp = { - let handler = json_tls.handler_mut(); - if !handler.is_timer_bound() { - handler.bind_timer(timer_borrow, DEFAULT_HEAD_TIMEOUT); - } - std::ptr::NonNull::from(handler.date_stamp()) - }; + let (json_tls, tls_stamp, h2c, h2) = if ports.h1_only { + ( + None::>, + h1_stamp, + None::, IdThru>>, + None::, TlsThru>>, + ) + } else { + let mut json_tls = { + let driver = exec.driver_mut(); + Listener::<2, _, TlsProd>::open_in( + tls_app::new::(&()), + listener_cfg(ports.json_tls_bind, cfg.max_conn), + driver, + )? + }; + json_tls.set_cfg(Endpoint::Server(Box::new(httparena_sark::tls::config( + vec![b"http/1.1".to_vec()], + )))); + let tls_stamp = { + let handler = json_tls.handler_mut(); + if !handler.is_timer_bound() { + handler.bind_timer(timer_borrow, DEFAULT_HEAD_TIMEOUT); + } + std::ptr::NonNull::from(handler.date_stamp()) + }; - let h2c = { - let driver = exec.driver_mut(); - Listener::<4, H2App<'_, BenchHandler, Identity>, IdThru>::open_in( - H2App::new(&h2c_handler), - listener_cfg(ports.h2c_bind, cfg.max_conn), - driver, - )? - }; + let h2c = { + let driver = exec.driver_mut(); + Listener::<4, H2App<'_, BenchHandler, Identity>, IdThru>::open_in( + H2App::new(&h2c_handler), + listener_cfg(ports.h2c_bind, cfg.max_conn), + driver, + )? + }; - let mut h2 = { - let driver = exec.driver_mut(); - Listener::<5, H2App<'_, BenchHandler, Tls>, TlsThru>::open_in( - H2App::new(&h2_handler), - listener_cfg(ports.h2_bind, cfg.max_conn), - driver, - )? + let mut h2 = { + let driver = exec.driver_mut(); + Listener::<5, H2App<'_, BenchHandler, Tls>, TlsThru>::open_in( + H2App::new(&h2_handler), + listener_cfg(ports.h2_bind, cfg.max_conn), + driver, + )? + }; + h2.set_cfg(Endpoint::Server(Box::new(httparena_sark::tls::config( + vec![b"h2".to_vec()], + )))); + (Some(json_tls), tls_stamp, Some(h2c), Some(h2)) }; - h2.set_cfg(Endpoint::Server(Box::new(httparena_sark::tls::config( - vec![b"h2".to_vec()], - )))); let mut init = app.as_mut().project(); init.date_h1.as_mut().get_mut().bind(h1_stamp); init.date_tls.as_mut().get_mut().bind(tls_stamp); init.p8080.set(Some(http)); - init.json_tls.set(Some(json_tls)); - init.h2c.set(Some(h2c)); - init.p8443.set(Some(h2)); + init.json_tls.set(json_tls); + init.h2c.set(h2c); + init.p8443.set(h2); exec.run(app.as_mut()) } @@ -979,11 +996,15 @@ fn main() -> io::Result<()> { .precompressed_gzip(), )); + let h1_only = std::env::var("SARK_HTTPARENA_H1_ONLY") + .map(|v| v == "1" || v.eq_ignore_ascii_case("true")) + .unwrap_or(false); let ports = PortArgs { h1_bind: boot.bind, json_tls_bind: SocketAddr::from(([0, 0, 0, 0], 8081)), h2c_bind: SocketAddr::from(([0, 0, 0, 0], 8082)), h2_bind: SocketAddr::from(([0, 0, 0, 0], 8443)), + h1_only, }; let cfg = ServerCfg { @@ -1006,6 +1027,7 @@ fn main() -> io::Result<()> { json_tls_bind: ports.json_tls_bind, h2c_bind: ports.h2c_bind, h2_bind: ports.h2_bind, + h1_only: ports.h1_only, }; run_thread(pg, ports, cfg.clone(), ctx) })