diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/COVENANT.md b/COVENANT.md new file mode 100644 index 0000000..7b8a57a --- /dev/null +++ b/COVENANT.md @@ -0,0 +1,23 @@ +# Covenant of Open Building + +This document states values. It grants no legal rights and restricts none. +The software license is Apache-2.0 (see LICENSE). Where this covenant and +LICENSE disagree, LICENSE governs. + +## The ask + +Keep foundational advances open. + +Organizations and individuals building on AIEN are asked, as a matter of +shared interest rather than legal obligation, to keep foundational +improvements available to the wider community: publish what the commons +needs to reproduce and extend the work, avoid enclosing shared advances +behind exclusive controls, and prefer rate and access policies that do not +discriminate against independent builders. + +## Scope + +This covenant binds no one. It modifies no Apache-2.0 rights, changes no +historical license, overrides no third-party terms of service, and creates +no damages or enforcement mechanism. Legal review of the licensing posture +is tracked separately and is not closed by this document. diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9e31f8d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1883 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "aien-edge" +version = "0.1.0" +dependencies = [ + "arc-swap", + "blake3", + "brotli", + "bytes", + "flate2", + "http", + "http-body-util", + "hyper", + "hyper-util", + "mime_guess", + "rustls-acme", + "serde", + "tempfile", + "tokio", + "tokio-rustls", + "tokio-stream", + "toml", + "tracing", + "tracing-subscriber", +] + +[[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 = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "arc-swap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" +dependencies = [ + "rustversion", +] + +[[package]] +name = "arrayvec" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" + +[[package]] +name = "asn1-rs" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8" +dependencies = [ + "asn1-rs-derive", + "asn1-rs-impl", + "displaydoc", + "nom", + "num-traits", + "rusticata-macros", + "thiserror 2.0.20", + "time", +] + +[[package]] +name = "asn1-rs-derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "asn1-rs-impl" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-http-codec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "096146020b08dbc4587685b0730a7ba905625af13c65f8028035cdfd69573c91" +dependencies = [ + "anyhow", + "futures", + "http", + "httparse", + "log", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-net" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "async-web-client" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8caf502b44d6d4be6154ac33af012cbb5fef11e6066edcfb42834217fbaf501b" +dependencies = [ + "async-http-codec", + "async-net", + "futures", + "futures-rustls", + "http", + "lazy_static", + "log", + "rustls-pki-types", + "serde", + "thiserror 1.0.69", + "webpki-roots 0.26.11", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "aws-lc-rs" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "blake3" +version = "1.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae" +dependencies = [ + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", + "cpufeatures", +] + +[[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[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 = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "windows-link", +] + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "constant_time_eq" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" + +[[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.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "der-parser" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6" +dependencies = [ + "asn1-rs", + "displaydoc", + "nom", + "num-bigint", + "num-traits", + "rusticata-macros", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b" + +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "futures-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f2f12607f92c69b12ed746fabf9ca4f5c482cba46679c1a75b874ed7c26adb" +dependencies = [ + "futures-io", + "rustls", + "rustls-pki-types", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "h2" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "oid-registry" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7" +dependencies = [ + "asn1-rs", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "pem" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" +dependencies = [ + "base64", + "serde_core", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rcgen" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75e669e5202259b5314d1ea5397316ad400819437857b90861765f24c4cf80a2" +dependencies = [ + "aws-lc-rs", + "pem", + "rustls-pki-types", + "time", + "yasna", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rusticata-macros" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" +dependencies = [ + "nom", +] + +[[package]] +name = "rustix" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +dependencies = [ + "aws-lc-rs", + "log", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-acme" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f24daec4ed0dfe6327bcb2b8045bf1d1cb4835e4f824d4cf487140f4b0cee4" +dependencies = [ + "async-io", + "async-trait", + "async-web-client", + "aws-lc-rs", + "base64", + "blocking", + "chrono", + "futures", + "futures-rustls", + "http", + "log", + "pem", + "rcgen", + "serde", + "serde_json", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "webpki-roots 1.0.9", + "x509-parser", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c85f2c3ef0b1cd58b36682f4b17aaa995f0e5db534d85692b4903abce21f67" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d06f0b082ba57c26b79407372e57cf2a1e28124f78e9479fe80322cf53420b" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.9", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +dependencies = [ + "memchr", +] + +[[package]] +name = "x509-parser" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202" +dependencies = [ + "asn1-rs", + "data-encoding", + "der-parser", + "lazy_static", + "nom", + "oid-registry", + "rusticata-macros", + "thiserror 2.0.20", + "time", +] + +[[package]] +name = "yasna" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" +dependencies = [ + "time", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3e4a2d8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "aien-edge" +version = "0.1.0" +edition = "2021" +description = "Native Rust edge server for AIEN static sites: in-memory precompressed assets, virtual hosts, and automatic Let's Encrypt TLS" +license = "Apache-2.0 WITH LLVM-exception" +authors = ["Drake Stapleton "] +repository = "https://github.com/aien-dev/aien-edge" + +[dependencies] +arc-swap = "1" +blake3 = "1" +brotli = "8" +bytes = "1" +flate2 = "1" +http = "1" +http-body-util = "0.1" +hyper = { version = "1", features = ["http1", "http2", "server"] } +hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1", "http2"] } +mime_guess = "2" +rustls-acme = { version = "0.15.4", features = ["tokio"] } +serde = { version = "1", features = ["derive"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "signal", "time", "sync"] } +tokio-rustls = "0.26" +tokio-stream = "0.1" +toml = "0.8" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +[dev-dependencies] +tempfile = "3" + +[profile.release] +opt-level = 3 +lto = true +codegen-units = 1 +strip = true +panic = "abort" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b43627f --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ +Apache License, Version 2.0 (with LLVM Exception), for aien-edge +Copyright (c) 2026 Drake Stapleton and AIEN Contributors. +Authored by Drake Stapleton in collaboration with AIEN. + +This Work is licensed under the Apache License, Version 2.0, with the LLVM +Exception stated below (SPDX: Apache-2.0 WITH LLVM-exception). Values and +anti-enclosure principles live in the nonbinding COVENANT.md, which grants +and restricts no legal rights. + +================================================================================ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may combine such Object form to produce an executable image, however +produced, and distribute the user's executable image without being required +to provide such portions of this Software in Source form. + +In addition, if you combine the software in any way with other software, you +may distribute the combined software without being required to provide the +Source form of any software other than this Software (or any Derivative +Works thereof), provided that you otherwise comply with the terms of the +Apache License, Version 2.0. diff --git a/README.md b/README.md index bcaf4d8..bb08d56 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,49 @@ # aien-edge -Native Rust edge server for AIEN static sites: in-memory precompressed assets, virtual hosts, automatic Let's Encrypt TLS + +A small native Rust edge server for the AIEN static sites (`www.aienos.com`, `www.drakestapleton.com`). It runs on a Raspberry Pi at the network edge so the NVIDIA DGX Spark never faces the internet. + +- **Everything in memory.** Each site is read once at startup, precompressed with brotli (quality 11) and gzip, and hashed for ETags. Requests never touch the disk. +- **Automatic HTTPS.** Let's Encrypt certificates through `rustls-acme` (TLS-ALPN-01 on port 443; port 80 only redirects). TLS is `rustls`; nothing is hand-rolled. +- **Virtual hosts.** Canonical host per site, apex to `www` 301 redirects, HTTP to HTTPS redirects, 421 for unknown hosts. +- **Small attack surface.** GET and HEAD only, traversal-safe path normalization against an in-memory map (no filesystem lookups per request), hidden files and source maps never loaded, header-read and TLS-handshake timeouts, a connection cap, and security headers (HSTS, nosniff, frame denial, referrer policy). +- **Zero-downtime deploys.** `SIGHUP` (`systemctl reload aien-edge`) reloads every site; if the new copy fails to load, the old one keeps serving. + +## Measured + +On the Spark (aarch64), serving both built sites from one process, HTTP/1.1 keep-alive, brotli: + +``` +$ ab -k -n 50000 -c 64 -H "Host: www.drakestapleton.com" -H "Accept-Encoding: br" http://127.0.0.1:18777/dad +Failed requests: 0 +Requests per second: 191460.85 [#/sec] (mean) +Time per request: 0.334 [ms] (mean) +VmRSS: 18276 kB (VmHWM 30452 kB) +``` + +A Pi will be slower than the Spark, and real visitors are bound by the home uplink long before either. + +## Build and test + +```bash +cargo test +cargo clippy --release -- -D warnings +cargo build --release # target/release/aien-edge, aarch64 builds run on a 64-bit Pi OS +``` + +## Deploy on the Pi + +```bash +sudo install -m 0755 target/release/aien-edge /usr/local/bin/aien-edge +sudo install -D -m 0644 deploy/config.example.toml /etc/aien-edge/config.toml +sudo install -m 0644 deploy/aien-edge.service /etc/systemd/system/aien-edge.service +sudo mkdir -p /srv/sites/releases +sudo systemctl daemon-reload && sudo systemctl enable --now aien-edge +``` + +Then publish each site from the Spark with `deploy/publish-site.sh `. Keep `production = false` (Let's Encrypt staging) until both hosts issue certificates, then switch to `true` and reload. + +Network: forward TCP 80 and 443 on the router to the Pi only, and point the DNS A records for both apex and `www` hosts at the public IP. The Pi reaches the Spark only for deploys, over the direct link. + +## License + +Apache License 2.0 with LLVM Exception. See [LICENSE](LICENSE). Values live in the nonbinding [COVENANT.md](COVENANT.md). diff --git a/deploy/aien-edge.service b/deploy/aien-edge.service new file mode 100644 index 0000000..388f751 --- /dev/null +++ b/deploy/aien-edge.service @@ -0,0 +1,37 @@ +[Unit] +Description=aien-edge static site server (www.aienos.com, www.drakestapleton.com) +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/aien-edge /etc/aien-edge/config.toml +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +RestartSec=2 + +# Runs as a throwaway user with no shell, no home, and no write access +# outside its certificate cache. +DynamicUser=yes +StateDirectory=aien-edge +AmbientCapabilities=CAP_NET_BIND_SERVICE +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +NoNewPrivileges=yes +ProtectSystem=strict +ProtectHome=yes +PrivateTmp=yes +PrivateDevices=yes +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectControlGroups=yes +RestrictAddressFamilies=AF_INET AF_INET6 +RestrictNamespaces=yes +LockPersonality=yes +MemoryDenyWriteExecute=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service +ReadOnlyPaths=/srv/sites +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target diff --git a/deploy/config.example.toml b/deploy/config.example.toml new file mode 100644 index 0000000..98ac0fa --- /dev/null +++ b/deploy/config.example.toml @@ -0,0 +1,23 @@ +# /etc/aien-edge/config.toml on the edge host (the Raspberry Pi). + +http_listen = "[::]:80" +max_connections = 2048 + +[tls] +https_listen = "[::]:443" +contact = "aien@aienos.com" +# systemd StateDirectory=aien-edge maps to /var/lib/aien-edge. +cache_dir = "/var/lib/aien-edge/acme" +# Start with false (Let's Encrypt staging) until both hosts issue cleanly, then set true. +production = false + +[[site]] +host = "www.aienos.com" +redirect_from = ["aienos.com"] +root = "/srv/sites/aienos.com" +spa = true + +[[site]] +host = "www.drakestapleton.com" +redirect_from = ["drakestapleton.com"] +root = "/srv/sites/drakestapleton.com" diff --git a/deploy/publish-site.sh b/deploy/publish-site.sh new file mode 100755 index 0000000..4dc3f64 --- /dev/null +++ b/deploy/publish-site.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Build a site on the Spark and publish it to the edge host, then hot-reload. +# +# deploy/publish-site.sh aienos.com ~/workspace/aienos.com +# deploy/publish-site.sh drakestapleton.com ~/workspace/drakestapleton.com +# +# EDGE_HOST defaults to the Pi on the direct Spark link. +set -euo pipefail + +name="${1:?site name, for example aienos.com}" +src="${2:?path to the site checkout}" +edge="${EDGE_HOST:-edge@10.10.10.2}" + +cd "$src" +npm ci --no-audit --no-fund +npm run build + +# Upload into a fresh release directory, then repoint the /srv/sites/ +# symlink atomically so visitors never see a half-copied site. The server holds +# every file in memory, so it keeps serving the old copy until the reload. +stamp="$(date -u +%Y%m%dT%H%M%SZ)" +rsync -a --delete dist/ "$edge:/srv/sites/releases/$name-$stamp/" +ssh "$edge" "set -e + cd /srv/sites + ln -sfn releases/$name-$stamp .next-$name + mv -T .next-$name $name + sudo systemctl reload aien-edge + ls -1d releases/$name-* | head -n -3 | xargs -r rm -rf" +echo "published $name ($stamp)" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9f5f1a8 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,83 @@ +//! TOML configuration for aien-edge. + +use serde::Deserialize; +use std::path::PathBuf; + +#[derive(Debug, Clone, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Config { + /// Address for plain HTTP. Serves redirects to HTTPS when `tls` is set, content otherwise. + #[serde(default = "default_http")] + pub http_listen: String, + /// TLS settings. Omit to run plain HTTP only (local testing, or behind a tunnel). + pub tls: Option, + /// Upper bound on concurrent connections across both listeners. + #[serde(default = "default_max_conns")] + pub max_connections: usize, + #[serde(rename = "site", default)] + pub sites: Vec, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Tls { + #[serde(default = "default_https")] + pub https_listen: String, + /// ACME account contact, for example "aien@aienos.com". + pub contact: String, + /// Directory where certificates and the ACME account key are cached. + pub cache_dir: PathBuf, + /// false uses the Let's Encrypt staging directory. + #[serde(default)] + pub production: bool, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Site { + /// Canonical host, for example "www.aienos.com". + pub host: String, + /// Hosts that permanently redirect to `host`, for example "aienos.com". + #[serde(default)] + pub redirect_from: Vec, + /// Directory holding the built site. + pub root: PathBuf, + /// Serve index.html for unknown paths (single page apps). Otherwise 404.html with status 404. + #[serde(default)] + pub spa: bool, +} + +fn default_http() -> String { + "[::]:80".into() +} +fn default_https() -> String { + "[::]:443".into() +} +fn default_max_conns() -> usize { + 2048 +} + +impl Config { + pub fn load(path: &std::path::Path) -> Result { + let text = + std::fs::read_to_string(path).map_err(|e| format!("read {}: {e}", path.display()))?; + let cfg: Config = + toml::from_str(&text).map_err(|e| format!("parse {}: {e}", path.display()))?; + if cfg.sites.is_empty() { + return Err("config has no [[site]] entries".into()); + } + Ok(cfg) + } + + /// Every host name that needs a certificate. + pub fn all_hosts(&self) -> Vec { + let mut hosts: Vec = self + .sites + .iter() + .flat_map(|s| std::iter::once(s.host.clone()).chain(s.redirect_from.iter().cloned())) + .collect(); + hosts.sort(); + hosts.dedup(); + hosts + } +} diff --git a/src/handler.rs b/src/handler.rs new file mode 100644 index 0000000..2a1521e --- /dev/null +++ b/src/handler.rs @@ -0,0 +1,242 @@ +//! Request handling: host routing, redirects, conditional GET, and encoding negotiation. + +use crate::site::{pick_encoding, Encoding, SiteFiles}; +use bytes::Bytes; +use http::{header, HeaderValue, Method, Request, Response, StatusCode}; +use http_body_util::Full; +use std::collections::HashMap; +use std::sync::Arc; + +pub struct Sites { + pub by_host: HashMap>, + /// Alias host to canonical host. + pub redirects: HashMap, +} + +#[derive(Clone, Copy)] +pub enum Scheme { + /// Plain HTTP on a TLS-enabled server: redirect everything to HTTPS. + HttpRedirect, + /// Plain HTTP without TLS configured: serve content. + HttpServe, + Https, +} + +pub fn handle(req: &Request, sites: &Sites, scheme: Scheme) -> Response> { + let host = request_host(req); + let path_and_query = req + .uri() + .path_and_query() + .map(|p| p.as_str()) + .unwrap_or("/"); + + if let Some(canonical) = sites.redirects.get(&host) { + return redirect(&format!("https://{canonical}{path_and_query}"), scheme); + } + let Some(site) = sites.by_host.get(&host) else { + return plain(StatusCode::MISDIRECTED_REQUEST, "unknown host\n", scheme); + }; + if let Scheme::HttpRedirect = scheme { + return redirect(&format!("https://{host}{path_and_query}"), scheme); + } + if req.method() != Method::GET && req.method() != Method::HEAD { + let mut r = plain( + StatusCode::METHOD_NOT_ALLOWED, + "method not allowed\n", + scheme, + ); + r.headers_mut() + .insert(header::ALLOW, HeaderValue::from_static("GET, HEAD")); + return r; + } + let Some((asset, code)) = site.resolve(req.uri().path()) else { + return plain(StatusCode::NOT_FOUND, "not found\n", scheme); + }; + + let mut builder = Response::builder() + .header(header::CONTENT_TYPE, &asset.content_type) + .header(header::ETAG, &asset.etag) + .header(header::CACHE_CONTROL, asset.cache_control) + .header(header::VARY, "Accept-Encoding"); + if code == 200 { + let inm = req + .headers() + .get(header::IF_NONE_MATCH) + .and_then(|v| v.to_str().ok()); + if inm.is_some_and(|v| { + v.split(',') + .any(|t| t.trim() == asset.etag || t.trim() == "*") + }) { + let mut r = builder + .status(StatusCode::NOT_MODIFIED) + .body(Full::new(Bytes::new())) + .unwrap(); + security_headers(&mut r, scheme); + return r; + } + } + let accept = req + .headers() + .get(header::ACCEPT_ENCODING) + .and_then(|v| v.to_str().ok()); + let body = match pick_encoding(accept, asset) { + Encoding::Brotli => { + builder = builder.header(header::CONTENT_ENCODING, "br"); + asset.br.clone().unwrap() + } + Encoding::Gzip => { + builder = builder.header(header::CONTENT_ENCODING, "gzip"); + asset.gzip.clone().unwrap() + } + Encoding::Identity => asset.body.clone(), + }; + builder = builder.header(header::CONTENT_LENGTH, body.len()); + let body = if req.method() == Method::HEAD { + Bytes::new() + } else { + body + }; + let mut r = builder.status(code).body(Full::new(body)).unwrap(); + security_headers(&mut r, scheme); + r +} + +fn request_host(req: &Request) -> String { + let raw = req + .uri() + .host() + .map(str::to_string) + .or_else(|| { + req.headers() + .get(header::HOST) + .and_then(|h| h.to_str().ok()) + .map(str::to_string) + }) + .unwrap_or_default(); + // Strip a port and any trailing dot, and compare case-insensitively. + let no_port = match raw.rsplit_once(':') { + Some((h, p)) if !h.contains(']') && p.chars().all(|c| c.is_ascii_digit()) => h.to_string(), + _ => raw, + }; + no_port.trim_end_matches('.').to_ascii_lowercase() +} + +fn redirect(location: &str, scheme: Scheme) -> Response> { + let mut r = Response::builder() + .status(StatusCode::MOVED_PERMANENTLY) + .header(header::LOCATION, location) + .header(header::CONTENT_LENGTH, 0) + .body(Full::new(Bytes::new())) + .unwrap(); + security_headers(&mut r, scheme); + r +} + +fn plain(status: StatusCode, msg: &'static str, scheme: Scheme) -> Response> { + let mut r = Response::builder() + .status(status) + .header(header::CONTENT_TYPE, "text/plain; charset=utf-8") + .header(header::CONTENT_LENGTH, msg.len()) + .body(Full::new(Bytes::from_static(msg.as_bytes()))) + .unwrap(); + security_headers(&mut r, scheme); + r +} + +fn security_headers(r: &mut Response>, scheme: Scheme) { + let h = r.headers_mut(); + h.insert(header::SERVER, HeaderValue::from_static("aien-edge")); + h.insert( + header::X_CONTENT_TYPE_OPTIONS, + HeaderValue::from_static("nosniff"), + ); + h.insert( + header::REFERRER_POLICY, + HeaderValue::from_static("strict-origin-when-cross-origin"), + ); + h.insert(header::X_FRAME_OPTIONS, HeaderValue::from_static("DENY")); + h.insert( + "permissions-policy", + HeaderValue::from_static("camera=(), microphone=(), geolocation=()"), + ); + if let Scheme::Https = scheme { + h.insert( + header::STRICT_TRANSPORT_SECURITY, + HeaderValue::from_static("max-age=31536000"), + ); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::site::SiteFiles; + + fn sites() -> (tempfile::TempDir, Sites) { + let dir = tempfile::tempdir().unwrap(); + std::fs::write(dir.path().join("index.html"), "x".repeat(3000)).unwrap(); + let s = Arc::new(SiteFiles::load(dir.path(), true).unwrap()); + let mut by_host = HashMap::new(); + by_host.insert("www.example.com".to_string(), s); + let mut redirects = HashMap::new(); + redirects.insert("example.com".to_string(), "www.example.com".to_string()); + (dir, Sites { by_host, redirects }) + } + + fn get(host: &str, path: &str) -> Request<()> { + Request::builder() + .uri(path) + .header("host", host) + .body(()) + .unwrap() + } + + #[test] + fn apex_redirects_to_canonical_https() { + let (_d, s) = sites(); + let r = handle(&get("Example.com.", "/a?b=1"), &s, Scheme::Https); + assert_eq!(r.status(), 301); + assert_eq!( + r.headers()[header::LOCATION], + "https://www.example.com/a?b=1" + ); + } + + #[test] + fn http_redirects_when_tls_enabled() { + let (_d, s) = sites(); + let r = handle(&get("www.example.com:80", "/x"), &s, Scheme::HttpRedirect); + assert_eq!(r.headers()[header::LOCATION], "https://www.example.com/x"); + } + + #[test] + fn serves_brotli_and_honors_etag() { + let (_d, s) = sites(); + let mut req = get("www.example.com", "/"); + req.headers_mut() + .insert(header::ACCEPT_ENCODING, HeaderValue::from_static("br")); + let r = handle(&req, &s, Scheme::Https); + assert_eq!(r.status(), 200); + assert_eq!(r.headers()[header::CONTENT_ENCODING], "br"); + assert!(r.headers().contains_key(header::STRICT_TRANSPORT_SECURITY)); + let etag = r.headers()[header::ETAG].clone(); + req.headers_mut().insert(header::IF_NONE_MATCH, etag); + assert_eq!(handle(&req, &s, Scheme::Https).status(), 304); + } + + #[test] + fn unknown_host_and_bad_method() { + let (_d, s) = sites(); + assert_eq!( + handle(&get("evil.test", "/"), &s, Scheme::Https).status(), + 421 + ); + let post = Request::builder() + .method("POST") + .uri("/") + .header("host", "www.example.com") + .body(()) + .unwrap(); + assert_eq!(handle(&post, &s, Scheme::Https).status(), 405); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..88f4c7f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,223 @@ +//! aien-edge: a small native edge server for AIEN static sites. +//! +//! Usage: aien-edge +//! Send SIGHUP to reload every site from disk after a deploy. + +mod config; +mod handler; +mod site; + +use arc_swap::ArcSwap; +use handler::{Scheme, Sites}; +use hyper::service::service_fn; +use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer}; +use hyper_util::server::conn::auto::Builder; +use rustls_acme::caches::DirCache; +use rustls_acme::{is_tls_alpn_challenge, AcmeConfig}; +use std::collections::HashMap; +use std::sync::Arc; +use std::time::Duration; +use tokio::net::TcpListener; +use tokio::sync::Semaphore; +use tokio_rustls::rustls::ServerConfig; +use tokio_rustls::LazyConfigAcceptor; +use tokio_stream::StreamExt; + +const HEADER_READ_TIMEOUT: Duration = Duration::from_secs(10); +const TLS_HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(10); + +fn load_sites(cfg: &config::Config) -> Result { + let mut by_host = HashMap::new(); + let mut redirects = HashMap::new(); + for s in &cfg.sites { + let files = site::SiteFiles::load(&s.root, s.spa)?; + tracing::info!(host = %s.host, files = files.files.len(), bytes = files.bytes_raw, "loaded site"); + by_host.insert(s.host.to_ascii_lowercase(), Arc::new(files)); + for alias in &s.redirect_from { + redirects.insert(alias.to_ascii_lowercase(), s.host.to_ascii_lowercase()); + } + } + Ok(Sites { by_host, redirects }) +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt() + .with_env_filter( + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()), + ) + .init(); + + let path = std::env::args() + .nth(1) + .unwrap_or_else(|| "/etc/aien-edge/config.toml".into()); + let cfg = match config::Config::load(std::path::Path::new(&path)) { + Ok(c) => c, + Err(e) => { + eprintln!("aien-edge: {e}"); + std::process::exit(2); + } + }; + let sites = match load_sites(&cfg) { + Ok(s) => Arc::new(ArcSwap::from_pointee(s)), + Err(e) => { + eprintln!("aien-edge: {e}"); + std::process::exit(2); + } + }; + let permits = Arc::new(Semaphore::new(cfg.max_connections)); + + // SIGHUP: reload sites from disk; keep serving the old copy if the new one fails to load. + { + let sites = sites.clone(); + let cfg = cfg.clone(); + tokio::spawn(async move { + let mut hup = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::hangup()) + .expect("SIGHUP handler"); + while hup.recv().await.is_some() { + match load_sites(&cfg) { + Ok(s) => { + sites.store(Arc::new(s)); + tracing::info!("reloaded sites"); + } + Err(e) => { + tracing::error!(error = %e, "reload failed; still serving previous sites") + } + } + } + }); + } + + let http_scheme = if cfg.tls.is_some() { + Scheme::HttpRedirect + } else { + Scheme::HttpServe + }; + let http = tokio::spawn(serve_plain( + cfg.http_listen.clone(), + sites.clone(), + permits.clone(), + http_scheme, + )); + + if let Some(tls) = cfg.tls.clone() { + let https = tokio::spawn(serve_tls( + tls, + cfg.all_hosts(), + sites.clone(), + permits.clone(), + )); + let _ = tokio::join!(http, https); + } else { + let _ = http.await; + } +} + +fn builder() -> Builder { + let mut b = Builder::new(TokioExecutor::new()); + b.http1() + .timer(TokioTimer::new()) + .header_read_timeout(HEADER_READ_TIMEOUT); + b.http2().timer(TokioTimer::new()); + b +} + +async fn serve_plain( + addr: String, + sites: Arc>, + permits: Arc, + scheme: Scheme, +) { + let listener = TcpListener::bind(&addr) + .await + .unwrap_or_else(|e| panic!("bind {addr}: {e}")); + tracing::info!(%addr, "http listening"); + loop { + let Ok((tcp, _)) = listener.accept().await else { + continue; + }; + let Ok(permit) = permits.clone().try_acquire_owned() else { + continue; + }; + let sites = sites.clone(); + tokio::spawn(async move { + let _permit = permit; + let _ = tcp.set_nodelay(true); + let svc = service_fn(move |req| { + let sites = sites.load(); + let resp = handler::handle(&req, &sites, scheme); + async move { Ok::<_, std::convert::Infallible>(resp) } + }); + let _ = builder().serve_connection(TokioIo::new(tcp), svc).await; + }); + } +} + +async fn serve_tls( + tls: config::Tls, + hosts: Vec, + sites: Arc>, + permits: Arc, +) { + let mut state = AcmeConfig::new(hosts) + .contact_push(format!("mailto:{}", tls.contact)) + .cache(DirCache::new(tls.cache_dir.clone())) + .directory_lets_encrypt(tls.production) + .state(); + let challenge_config = state.challenge_rustls_config(); + let mut server_config = ServerConfig::builder() + .with_no_client_auth() + .with_cert_resolver(state.resolver()); + server_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + let server_config = Arc::new(server_config); + + tokio::spawn(async move { + while let Some(event) = state.next().await { + match event { + Ok(ok) => tracing::info!(event = ?ok, "acme"), + Err(err) => tracing::error!(error = ?err, "acme"), + } + } + }); + + let addr = tls.https_listen.clone(); + let listener = TcpListener::bind(&addr) + .await + .unwrap_or_else(|e| panic!("bind {addr}: {e}")); + tracing::info!(%addr, production = tls.production, "https listening"); + loop { + let Ok((tcp, _)) = listener.accept().await else { + continue; + }; + let Ok(permit) = permits.clone().try_acquire_owned() else { + continue; + }; + let sites = sites.clone(); + let challenge_config = challenge_config.clone(); + let server_config = server_config.clone(); + tokio::spawn(async move { + let _permit = permit; + let _ = tcp.set_nodelay(true); + let handshake = async { + let start = LazyConfigAcceptor::new(Default::default(), tcp) + .await + .ok()?; + if is_tls_alpn_challenge(&start.client_hello()) { + let _ = start.into_stream(challenge_config).await; + return None; + } + start.into_stream(server_config).await.ok() + }; + let Ok(Some(stream)) = tokio::time::timeout(TLS_HANDSHAKE_TIMEOUT, handshake).await + else { + return; + }; + let svc = service_fn(move |req| { + let sites = sites.load(); + let resp = handler::handle(&req, &sites, Scheme::Https); + async move { Ok::<_, std::convert::Infallible>(resp) } + }); + let _ = builder().serve_connection(TokioIo::new(stream), svc).await; + }); + } +} diff --git a/src/site.rs b/src/site.rs new file mode 100644 index 0000000..8b3397c --- /dev/null +++ b/src/site.rs @@ -0,0 +1,305 @@ +//! In-memory site store. Every file is read once at load, precompressed, and +//! hashed, so serving a request never touches the disk. + +use bytes::Bytes; +use std::collections::HashMap; +use std::io::Write; +use std::path::Path; + +/// Files smaller than this are served uncompressed; the headers would cost more than the savings. +const COMPRESS_MIN: usize = 1024; + +#[derive(Debug)] +pub struct Asset { + pub body: Bytes, + pub br: Option, + pub gzip: Option, + pub content_type: String, + pub etag: String, + pub cache_control: &'static str, +} + +#[derive(Debug)] +pub struct SiteFiles { + /// Keyed by URL path without the leading slash, for example "assets/index-abc.js". + pub files: HashMap, + pub spa: bool, + pub bytes_raw: usize, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Encoding { + Brotli, + Gzip, + Identity, +} + +impl SiteFiles { + pub fn load(root: &Path, spa: bool) -> Result { + let mut files = HashMap::new(); + let mut bytes_raw = 0; + walk(root, root, &mut files, &mut bytes_raw)?; + if !files.contains_key("index.html") { + return Err(format!("{} has no index.html", root.display())); + } + Ok(SiteFiles { + files, + spa, + bytes_raw, + }) + } + + /// Resolve a request path to an asset and the status to serve it with. + /// Returns None when nothing matches and the site has no 404 page. + pub fn resolve(&self, path: &str) -> Option<(&Asset, u16)> { + let key = normalize(path)?; + let candidates = [ + key.clone(), + if key.is_empty() { + "index.html".into() + } else { + format!("{key}/index.html") + }, + format!("{key}.html"), + ]; + for c in candidates.iter() { + if let Some(a) = self.files.get(c.trim_start_matches('/')) { + return Some((a, 200)); + } + } + if self.spa { + return self.files.get("index.html").map(|a| (a, 200)); + } + self.files.get("404.html").map(|a| (a, 404)) + } +} + +/// Decode and normalize a URL path. Rejects traversal and anything outside the site. +pub fn normalize(path: &str) -> Option { + let path = path.split(['?', '#']).next().unwrap_or(""); + let decoded = percent_decode(path)?; + let mut parts: Vec<&str> = Vec::new(); + for seg in decoded.split('/') { + match seg { + "" | "." => {} + ".." => return None, + s if s.contains('\\') || s.contains('\0') => return None, + s => parts.push(s), + } + } + Some(parts.join("/")) +} + +fn percent_decode(s: &str) -> Option { + let bytes = s.as_bytes(); + let mut out = Vec::with_capacity(bytes.len()); + let mut i = 0; + while i < bytes.len() { + if bytes[i] == b'%' { + let hex = s.get(i + 1..i + 3)?; + out.push(u8::from_str_radix(hex, 16).ok()?); + i += 3; + } else { + out.push(bytes[i]); + i += 1; + } + } + String::from_utf8(out).ok() +} + +pub fn pick_encoding(accept: Option<&str>, asset: &Asset) -> Encoding { + let Some(accept) = accept else { + return Encoding::Identity; + }; + let allows = |name: &str| { + accept.split(',').any(|tok| { + let mut it = tok.trim().split(';'); + let coding = it.next().unwrap_or("").trim(); + let q_zero = it.any(|p| { + let p = p.trim(); + p == "q=0" || p == "q=0.0" || p == "q=0.00" || p == "q=0.000" + }); + coding.eq_ignore_ascii_case(name) && !q_zero + }) + }; + if asset.br.is_some() && allows("br") { + Encoding::Brotli + } else if asset.gzip.is_some() && allows("gzip") { + Encoding::Gzip + } else { + Encoding::Identity + } +} + +fn walk( + root: &Path, + dir: &Path, + out: &mut HashMap, + total: &mut usize, +) -> Result<(), String> { + let entries = std::fs::read_dir(dir).map_err(|e| format!("read_dir {}: {e}", dir.display()))?; + for entry in entries { + let entry = entry.map_err(|e| e.to_string())?; + let path = entry.path(); + let ft = entry.file_type().map_err(|e| e.to_string())?; + if ft.is_symlink() { + continue; + } + if ft.is_dir() { + walk(root, &path, out, total)?; + continue; + } + let rel = path + .strip_prefix(root) + .map_err(|e| e.to_string())? + .to_string_lossy() + .replace('\\', "/"); + if rel.ends_with(".map") + || rel + .split('/') + .any(|s| s.starts_with('.') && s != ".well-known") + { + continue; + } + let body = std::fs::read(&path).map_err(|e| format!("read {}: {e}", path.display()))?; + *total += body.len(); + out.insert(rel.clone(), build_asset(&rel, body)); + } + Ok(()) +} + +fn build_asset(rel: &str, body: Vec) -> Asset { + let mime = mime_guess::from_path(rel).first_or_octet_stream(); + let text_like = mime.type_() == "text" + || matches!( + mime.subtype().as_str(), + "javascript" | "json" | "xml" | "svg" + ) + || mime.essence_str() == "image/svg+xml" + || rel.ends_with(".webmanifest"); + let content_type = if mime.type_() == "text" || mime.subtype() == "javascript" { + format!("{}; charset=utf-8", mime.essence_str()) + } else { + mime.essence_str().to_string() + }; + let (br, gzip) = if text_like && body.len() >= COMPRESS_MIN { + let br = brotli_bytes(&body); + let gz = gzip_bytes(&body); + ( + (br.len() < body.len()).then(|| Bytes::from(br)), + (gz.len() < body.len()).then(|| Bytes::from(gz)), + ) + } else { + (None, None) + }; + let etag = format!("\"{}\"", &blake3::hash(&body).to_hex()[..20]); + // Vite emits content-hashed names under assets/, so they can be cached forever. + let cache_control = if rel.starts_with("assets/") { + "public, max-age=31536000, immutable" + } else if rel.ends_with(".html") { + "public, max-age=0, must-revalidate" + } else { + "public, max-age=3600" + }; + Asset { + body: Bytes::from(body), + br, + gzip, + content_type, + etag, + cache_control, + } +} + +fn brotli_bytes(data: &[u8]) -> Vec { + let mut out = Vec::with_capacity(data.len() / 3); + { + let mut w = brotli::CompressorWriter::new(&mut out, 4096, 11, 22); + w.write_all(data).expect("brotli write to Vec"); + } + out +} + +fn gzip_bytes(data: &[u8]) -> Vec { + let mut enc = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::best()); + enc.write_all(data).expect("gzip write to Vec"); + enc.finish().expect("gzip finish") +} + +#[cfg(test)] +mod tests { + use super::*; + + fn site(files: &[(&str, &str)], spa: bool) -> (tempfile::TempDir, SiteFiles) { + let dir = tempfile::tempdir().unwrap(); + for (p, c) in files { + let full = dir.path().join(p); + std::fs::create_dir_all(full.parent().unwrap()).unwrap(); + std::fs::write(full, c).unwrap(); + } + let s = SiteFiles::load(dir.path(), spa).unwrap(); + (dir, s) + } + + #[test] + fn normalize_rejects_traversal() { + assert_eq!(normalize("/a/../b"), None); + assert_eq!(normalize("/%2e%2e/etc/passwd"), None); + assert_eq!(normalize("/a%5cb"), None); + assert_eq!(normalize("/a//b/./c?x=1"), Some("a/b/c".into())); + assert_eq!(normalize("/"), Some("".into())); + } + + #[test] + fn resolves_prerendered_routes_and_404() { + let (_d, s) = site( + &[ + ("index.html", "home"), + ("dad/index.html", "dad"), + ("404.html", "nf"), + ], + false, + ); + assert_eq!(s.resolve("/").unwrap().1, 200); + assert_eq!(&s.resolve("/dad").unwrap().0.body[..], b"dad"); + assert_eq!(&s.resolve("/dad/").unwrap().0.body[..], b"dad"); + let (a, code) = s.resolve("/missing").unwrap(); + assert_eq!((&a.body[..], code), (&b"nf"[..], 404)); + } + + #[test] + fn spa_falls_back_to_index() { + let (_d, s) = site(&[("index.html", "app")], true); + let (a, code) = s.resolve("/deep/link").unwrap(); + assert_eq!((&a.body[..], code), (&b"app"[..], 200)); + } + + #[test] + fn hidden_files_and_sourcemaps_are_not_served() { + let (_d, s) = site( + &[ + ("index.html", "x"), + (".env", "secret"), + ("assets/a.js.map", "{}"), + ], + false, + ); + assert!(!s.files.contains_key(".env")); + assert!(!s.files.contains_key("assets/a.js.map")); + } + + #[test] + fn encoding_negotiation() { + let big = "x".repeat(4096); + let (_d, s) = site(&[("index.html", &big)], false); + let a = s.files.get("index.html").unwrap(); + assert_eq!( + pick_encoding(Some("gzip, deflate, br"), a), + Encoding::Brotli + ); + assert_eq!(pick_encoding(Some("gzip"), a), Encoding::Gzip); + assert_eq!(pick_encoding(Some("br;q=0, gzip"), a), Encoding::Gzip); + assert_eq!(pick_encoding(None, a), Encoding::Identity); + assert_eq!(a.cache_control, "public, max-age=0, must-revalidate"); + } +}