From ce68f4dd429500708654a6fa9c8ba53c745b764d Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Thu, 2 Jun 2022 21:58:56 -0700 Subject: [PATCH] Migrate to axum --- Cargo.lock | 1387 ++++++++---------------------------------- Cargo.toml | 7 +- src/config.rs | 119 ++-- src/error.rs | 4 +- src/main.rs | 108 ++-- src/routes.rs | 191 +++--- src/template_args.rs | 19 +- 7 files changed, 497 insertions(+), 1338 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ef01d9..c165c42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,295 +3,16 @@ version = 3 [[package]] -name = "actix-codec" -version = "0.3.0" +name = "anyhow" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d1833b3838dbe990df0f1f87baf640cf6146e898166afe401839d1b001e570" -dependencies = [ - "bitflags", - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project 0.4.29", - "tokio", - "tokio-util", -] +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" [[package]] -name = "actix-connect" -version = "2.0.0" +name = "arc-swap" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-utils", - "derive_more", - "either", - "futures-util", - "http", - "log", - "trust-dns-proto", - "trust-dns-resolver", -] - -[[package]] -name = "actix-http" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be6b66b62a794a8e6d366ac9415bb7d475ffd1e9f4671f38c1d8a8a5df950b3" -dependencies = [ - "actix-codec", - "actix-connect", - "actix-rt", - "actix-service", - "actix-threadpool", - "actix-utils", - "base64", - "bitflags", - "brotli", - "bytes 0.5.6", - "cookie", - "copyless", - "derive_more", - "either", - "encoding_rs", - "flate2", - "futures-channel", - "futures-core", - "futures-util", - "fxhash", - "h2", - "http", - "httparse", - "indexmap", - "itoa 0.4.8", - "language-tags", - "lazy_static", - "log", - "mime", - "percent-encoding", - "pin-project 1.0.10", - "rand", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "sha-1 0.9.8", - "slab", - "time 0.2.27", -] - -[[package]] -name = "actix-macros" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "actix-router" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad299af73649e1fc893e333ccf86f377751eb95ff875d095131574c6f43452c" -dependencies = [ - "bytestring", - "http", - "log", - "regex", - "serde", -] - -[[package]] -name = "actix-rt" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227" -dependencies = [ - "actix-macros", - "actix-threadpool", - "copyless", - "futures-channel", - "futures-util", - "smallvec", - "tokio", -] - -[[package]] -name = "actix-server" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-utils", - "futures-channel", - "futures-util", - "log", - "mio", - "mio-uds", - "num_cpus", - "slab", - "socket2", -] - -[[package]] -name = "actix-service" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb" -dependencies = [ - "futures-util", - "pin-project 0.4.29", -] - -[[package]] -name = "actix-testing" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c" -dependencies = [ - "actix-macros", - "actix-rt", - "actix-server", - "actix-service", - "log", - "socket2", -] - -[[package]] -name = "actix-threadpool" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d209f04d002854b9afd3743032a27b066158817965bf5d036824d19ac2cc0e30" -dependencies = [ - "derive_more", - "futures-channel", - "lazy_static", - "log", - "num_cpus", - "parking_lot", - "threadpool", -] - -[[package]] -name = "actix-tls" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24789b7d7361cf5503a504ebe1c10806896f61e96eca9a7350e23001aca715fb" -dependencies = [ - "actix-codec", - "actix-service", - "actix-utils", - "futures-util", -] - -[[package]] -name = "actix-utils" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "bitflags", - "bytes 0.5.6", - "either", - "futures-channel", - "futures-sink", - "futures-util", - "log", - "pin-project 0.4.29", - "slab", -] - -[[package]] -name = "actix-web" -version = "3.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6534a126df581caf443ba2751cab42092c89b3f1d06a9d829b1e17edfe3e277" -dependencies = [ - "actix-codec", - "actix-http", - "actix-macros", - "actix-router", - "actix-rt", - "actix-server", - "actix-service", - "actix-testing", - "actix-threadpool", - "actix-tls", - "actix-utils", - "actix-web-codegen", - "awc", - "bytes 0.5.6", - "derive_more", - "encoding_rs", - "futures-channel", - "futures-core", - "futures-util", - "fxhash", - "log", - "mime", - "pin-project 1.0.10", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "socket2", - "time 0.2.27", - "tinyvec", - "url", -] - -[[package]] -name = "actix-web-codegen" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] -name = "alloc-no-stdlib" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ef4730490ad1c4eae5c4325b2a95f521d023e5c885853ff7aca0a6a1631db3" - -[[package]] -name = "alloc-stdlib" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697ed7edc0f1711de49ce108c541623a0af97c6c60b2f6e2b65229847ac843c2" -dependencies = [ - "alloc-no-stdlib", -] +checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f" [[package]] name = "async-trait" @@ -322,40 +43,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "awc" -version = "2.0.3" +name = "axum" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691" +checksum = "ab2504b827a8bef941ba3dd64bdffe9cf56ca182908a147edd6189c95fbcae7d" dependencies = [ - "actix-codec", - "actix-http", - "actix-rt", - "actix-service", - "base64", - "bytes 0.5.6", - "cfg-if 1.0.0", - "derive_more", - "futures-core", - "log", + "async-trait", + "axum-core", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", "mime", "percent-encoding", - "rand", + "pin-project-lite", "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-http", + "tower-layer", + "tower-service", ] [[package]] -name = "base-x" -version = "0.2.10" +name = "axum-core" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" - -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "da31c0ed7b4690e2c78fe4b880d21cd7db04a346ebc658b4270251b695437f17" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", +] [[package]] name = "bitflags" @@ -372,16 +102,7 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array 0.12.4", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array 0.14.5", + "generic-array", ] [[package]] @@ -393,38 +114,13 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "brotli" -version = "3.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", - "brotli-decompressor", -] - -[[package]] -name = "brotli-decompressor" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ad2d4653bf5ca36ae797b1f4bb4dbddb60ce49ca4aed8a2ce4829f60425b80" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", -] - -[[package]] -name = "bumpalo" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - [[package]] name = "bunbun" version = "0.8.0" dependencies = [ - "actix-web", + "anyhow", + "arc-swap", + "axum", "clap", "dirs", "handlebars", @@ -436,6 +132,7 @@ dependencies = [ "serde_yaml", "simple_logger", "tempfile", + "tokio", ] [[package]] @@ -450,27 +147,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" -[[package]] -name = "bytestring" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d" -dependencies = [ - "bytes 1.1.0", -] - [[package]] name = "cfg-if" version = "0.1.10" @@ -534,82 +216,13 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "cookie" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" -dependencies = [ - "percent-encoding", - "time 0.2.27", - "version_check", -] - -[[package]] -name = "copyless" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" - -[[package]] -name = "cpufeatures" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn", -] - [[package]] name = "digest" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array 0.12.4", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.5", + "generic-array", ] [[package]] @@ -632,39 +245,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "enum-as-inner" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570d109b813e904becc80d8d5da38376818a143348413f7149f1340fe04754d4" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -692,16 +272,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "flate2" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" @@ -753,20 +323,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.21" @@ -774,7 +330,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -783,23 +338,6 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" -[[package]] -name = "futures-io" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" - -[[package]] -name = "futures-macro" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "futures-sink" version = "0.3.21" @@ -818,25 +356,10 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite", "pin-utils", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", ] [[package]] @@ -848,27 +371,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "generic-array" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.6" @@ -880,26 +382,6 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] -[[package]] -name = "h2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", - "tracing-futures", -] - [[package]] name = "handlebars" version = "4.3.0" @@ -935,17 +417,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hostname" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" -dependencies = [ - "libc", - "match_cfg", - "winapi 0.3.9", -] - [[package]] name = "hotwatch" version = "0.4.6" @@ -962,11 +433,28 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", - "itoa 1.0.2", + "itoa", ] +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + [[package]] name = "httparse" version = "1.7.1" @@ -974,14 +462,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] -name = "idna" -version = "0.2.3" +name = "httpdate" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dc3c131584288d375f2d07f822b0cb012d8c6fb899a5b9fdb3cb7eb9b6004f" dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", ] [[package]] @@ -1032,24 +538,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipconfig" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" -dependencies = [ - "socket2", - "widestring", - "winapi 0.3.9", - "winreg", -] - -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - [[package]] name = "itoa" version = "1.0.2" @@ -1066,12 +554,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -1115,33 +597,24 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "lru-cache" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "maplit" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - [[package]] name = "matches" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "matchit" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" + [[package]] name = "memchr" version = "2.5.0" @@ -1154,15 +627,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "miniz_oxide" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" -dependencies = [ - "adler", -] - [[package]] name = "mio" version = "0.6.23" @@ -1182,6 +646,18 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", +] + [[package]] name = "mio-extras" version = "2.0.6" @@ -1190,21 +666,10 @@ checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", "log", - "mio", + "mio 0.6.23", "slab", ] -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio", -] - [[package]] name = "miow" version = "0.2.2" @@ -1240,7 +705,7 @@ dependencies = [ "fsevent-sys", "inotify", "libc", - "mio", + "mio 0.6.23", "mio-extras", "walkdir", "winapi 0.3.9", @@ -1265,18 +730,18 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" + [[package]] name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "os_str_bytes" version = "6.1.0" @@ -1285,27 +750,25 @@ checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ "cfg-if 1.0.0", - "instant", "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "windows-sys", ] [[package]] @@ -1354,16 +817,7 @@ checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" dependencies = [ "maplit", "pest", - "sha-1 0.8.2", -] - -[[package]] -name = "pin-project" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" -dependencies = [ - "pin-project-internal 0.4.29", + "sha-1", ] [[package]] @@ -1372,18 +826,7 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" dependencies = [ - "pin-project-internal 1.0.10", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] @@ -1397,12 +840,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1415,12 +852,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "ppv-lite86" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1445,12 +876,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - [[package]] name = "proc-macro2" version = "1.0.39" @@ -1460,12 +885,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.18" @@ -1475,47 +894,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.2.13" @@ -1531,28 +909,11 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.6", + "getrandom", "redox_syscall", "thiserror", ] -[[package]] -name = "regex" -version = "1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" - [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1562,34 +923,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "resolv-conf" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" -dependencies = [ - "hostname", - "quick-error", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.9", -] - [[package]] name = "ryu" version = "1.0.10" @@ -1611,27 +944,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.137" @@ -1658,7 +970,7 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ - "itoa 1.0.2", + "itoa", "ryu", "serde", ] @@ -1670,7 +982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.2", + "itoa", "ryu", "serde", ] @@ -1693,40 +1005,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", + "block-buffer", + "digest", "fake-simd", - "opaque-debug 0.2.3", + "opaque-debug", ] -[[package]] -name = "sha-1" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1745,7 +1029,7 @@ dependencies = [ "atty", "colored", "log", - "time 0.3.9", + "time", "winapi 0.3.9", ] @@ -1763,73 +1047,14 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "socket2" -version = "0.3.19" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ - "cfg-if 1.0.0", "libc", "winapi 0.3.9", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "strsim" version = "0.10.0" @@ -1847,6 +1072,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" + [[package]] name = "tempfile" version = "3.3.0" @@ -1909,50 +1140,16 @@ dependencies = [ "syn", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "time" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros 0.1.1", - "version_check", - "winapi 0.3.9", -] - [[package]] name = "time" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" dependencies = [ - "itoa 1.0.2", + "itoa", "libc", "num_threads", - "time-macros 0.2.4", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", + "time-macros", ] [[package]] @@ -1961,68 +1158,98 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" -[[package]] -name = "time-macros-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - [[package]] name = "tokio" -version = "0.2.25" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ - "bytes 0.5.6", - "futures-core", - "iovec", - "lazy_static", + "bytes", "libc", "memchr", - "mio", - "mio-uds", - "pin-project-lite 0.1.12", + "mio 0.8.3", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", "signal-hook-registry", - "slab", + "socket2", + "tokio-macros", "winapi 0.3.9", ] [[package]] -name = "tokio-util" -version = "0.3.1" +name = "tokio-macros" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ - "bytes 0.5.6", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c" +dependencies = [ + "bytes", "futures-core", "futures-sink", - "log", - "pin-project-lite 0.1.12", + "pin-project-lite", "tokio", ] +[[package]] +name = "tower" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + [[package]] name = "tracing" version = "0.1.34" @@ -2031,7 +1258,7 @@ checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.9", + "pin-project-lite", "tracing-core", ] @@ -2045,53 +1272,10 @@ dependencies = [ ] [[package]] -name = "tracing-futures" -version = "0.2.5" +name = "try-lock" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project 1.0.10", - "tracing", -] - -[[package]] -name = "trust-dns-proto" -version = "0.19.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9" -dependencies = [ - "async-trait", - "cfg-if 1.0.0", - "enum-as-inner", - "futures", - "idna", - "lazy_static", - "log", - "rand", - "smallvec", - "thiserror", - "tokio", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.19.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" -dependencies = [ - "cfg-if 0.1.10", - "futures", - "ipconfig", - "lazy_static", - "log", - "lru-cache", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "trust-dns-proto", -] +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" @@ -2105,39 +1289,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" -[[package]] -name = "unicode-bidi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" - [[package]] name = "unicode-ident" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" -[[package]] -name = "unicode-normalization" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - [[package]] name = "version_check" version = "0.9.4" @@ -2156,10 +1313,14 @@ dependencies = [ ] [[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +name = "want" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] [[package]] name = "wasi" @@ -2168,64 +1329,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] -name = "wasm-bindgen" -version = "0.2.80" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" - -[[package]] -name = "widestring" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" @@ -2271,14 +1378,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "winreg" -version = "0.6.2" +name = "windows-sys" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "winapi 0.3.9", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", ] +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 71c1036..4a72dd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,14 +10,17 @@ repository = "https://github.com/edward-shen/bunbun" exclude = ["/aux/"] [dependencies] -actix-web = "3" +anyhow = "1" +arc-swap = "1" +tokio = { version = "1", features = ["full"] } +axum = "0.5" clap = { version = "3", features = ["wrap_help", "derive", "cargo"] } dirs = "4" handlebars = "4" hotwatch = "0.4" log = "0.4" percent-encoding = "2" -serde = "1" +serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" serde_json = "1" simple_logger = "2" diff --git a/src/config.rs b/src/config.rs index ba9f300..61cadc8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,6 +60,32 @@ impl FromStr for Route { } } +impl From for Route { + fn from(s: String) -> Self { + Self { + route_type: get_route_type(&s), + path: s, + hidden: false, + description: None, + min_args: None, + max_args: None, + } + } +} + +impl From<&'static str> for Route { + fn from(s: &'static str) -> Self { + Self { + route_type: get_route_type(s), + path: s.to_string(), + hidden: false, + description: None, + min_args: None, + max_args: None, + } + } +} + /// Deserialization of the route string into the enum requires us to figure out /// whether or not the string is valid to run as an executable or not. To /// determine this, we simply check if it exists on disk or assume that it's a @@ -147,8 +173,7 @@ impl<'de> Deserialize<'de> for Route { { return Err(de::Error::invalid_value( Unexpected::Other(&format!( - "argument count range {} to {}", - min_args, max_args + "argument count range {min_args} to {max_args}", )), &"a valid argument count range", )); @@ -179,12 +204,12 @@ impl std::fmt::Display for Route { route_type: RouteType::External, path, .. - } => write!(f, "raw ({})", path), + } => write!(f, "raw ({path})"), Self { route_type: RouteType::Internal, path, .. - } => write!(f, "file ({})", path), + } => write!(f, "file ({path})"), } } } @@ -192,10 +217,10 @@ impl std::fmt::Display for Route { /// Classifies the path depending on if the there exists a local file. fn get_route_type(path: &str) -> RouteType { if std::path::Path::new(path).exists() { - debug!("Parsed {} as a valid local path.", path); + debug!("Parsed {path} as a valid local path."); RouteType::Internal } else { - debug!("{} does not exist on disk, assuming web path.", path); + debug!("{path} does not exist on disk, assuming web path."); RouteType::External } } @@ -245,16 +270,15 @@ pub fn get_config_data() -> Result { let file = OpenOptions::new().read(true).open(location.clone()); match file { Ok(file) => { - debug!("Found file at {:?}.", location); + debug!("Found file at {location:?}."); return Ok(ConfigData { path: location.clone(), file, }); } - Err(e) => debug!( - "Tried to read '{:?}' but failed due to error: {}", - location, e - ), + Err(e) => { + debug!("Tried to read '{location:?}' but failed due to error: {e}",) + } } } @@ -270,7 +294,7 @@ pub fn get_config_data() -> Result { .open(location.clone()); match file { Ok(mut file) => { - info!("Creating new config file at {:?}.", location); + info!("Creating new config file at {location:?}."); file.write_all(DEFAULT_CONFIG)?; let file = OpenOptions::new().read(true).open(location.clone())?; @@ -280,8 +304,7 @@ pub fn get_config_data() -> Result { }); } Err(e) => debug!( - "Tried to open a new file at '{:?}' but failed due to error: {}", - location, e + "Tried to open a new file at '{location:?}' but failed due to error: {e}", ), } } @@ -329,90 +352,96 @@ pub fn read_config( #[cfg(test)] mod route { use super::*; + use anyhow::{Context, Result}; use serde_yaml::{from_str, to_string}; use tempfile::NamedTempFile; #[test] - fn deserialize_relative_path() { - let tmpfile = NamedTempFile::new_in(".").unwrap(); + fn deserialize_relative_path() -> Result<()> { + let tmpfile = NamedTempFile::new_in(".")?; let path = format!("{}", tmpfile.path().display()); - let path = path.get(path.rfind(".").unwrap()..).unwrap(); + let path = path + .get(path.rfind(".").context("While finding .")?..) + .context("While getting the path")?; let path = std::path::Path::new(path); assert!(path.is_relative()); - let path = path.to_str().unwrap(); - assert_eq!( - from_str::(path).unwrap(), - Route::from_str(path).unwrap() - ); + let path = path.to_str().context("While stringifying path")?; + assert_eq!(from_str::(path)?, Route::from_str(path)?); + Ok(()) } #[test] - fn deserialize_absolute_path() { - let tmpfile = NamedTempFile::new().unwrap(); + fn deserialize_absolute_path() -> Result<()> { + let tmpfile = NamedTempFile::new()?; let path = format!("{}", tmpfile.path().display()); assert!(tmpfile.path().is_absolute()); - assert_eq!( - from_str::(&path).unwrap(), - Route::from_str(&path).unwrap() - ); + assert_eq!(from_str::(&path)?, Route::from_str(&path)?); + + Ok(()) } #[test] - fn deserialize_http_path() { + fn deserialize_http_path() -> Result<()> { assert_eq!( - from_str::("http://google.com").unwrap(), - Route::from_str("http://google.com").unwrap() + from_str::("http://google.com")?, + Route::from_str("http://google.com")? ); + Ok(()) } #[test] - fn deserialize_https_path() { + fn deserialize_https_path() -> Result<()> { assert_eq!( - from_str::("https://google.com").unwrap(), - Route::from_str("https://google.com").unwrap() + from_str::("https://google.com")?, + Route::from_str("https://google.com")? ); + Ok(()) } #[test] - fn serialize() { + fn serialize() -> Result<()> { assert_eq!( - &to_string(&Route::from_str("hello world").unwrap()).unwrap(), + &to_string(&Route::from_str("hello world")?)?, "---\nroute_type: External\npath: hello world\nhidden: false\ndescription: ~\nmin_args: ~\nmax_args: ~\n" ); + Ok(()) } } #[cfg(test)] mod read_config { use super::*; + use anyhow::Result; #[test] - fn empty_file() { - let config_file = tempfile::tempfile().unwrap(); + fn empty_file() -> Result<()> { + let config_file = tempfile::tempfile()?; assert!(matches!( read_config(config_file, false), Err(BunBunError::ZeroByteConfig) )); + Ok(()) } #[test] - fn config_too_large() { - let mut config_file = tempfile::tempfile().unwrap(); + fn config_too_large() -> Result<()> { + let mut config_file = tempfile::tempfile()?; let size_to_write = (LARGE_FILE_SIZE_THRESHOLD + 1) as usize; - config_file.write(&[0].repeat(size_to_write)).unwrap(); + config_file.write(&[0].repeat(size_to_write))?; match read_config(config_file, false) { Err(BunBunError::ConfigTooLarge(size)) if size as usize == size_to_write => {} Err(BunBunError::ConfigTooLarge(size)) => { panic!("Mismatched size: {} != {}", size, size_to_write) } - res => panic!("Wrong result, got {:#?}", res), + res => panic!("Wrong result, got {res:#?}"), } + Ok(()) } #[test] - fn valid_config() { - let config_file = File::open("bunbun.default.yaml").unwrap(); - assert!(read_config(config_file, false).is_ok()); + fn valid_config() -> Result<()> { + assert!(read_config(File::open("bunbun.default.yaml")?, false).is_ok()); + Ok(()) } } diff --git a/src/error.rs b/src/error.rs index 48c51bd..9644bf9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,9 +27,9 @@ impl fmt::Display for BunBunError { Self::CustomProgram(msg) => write!(f, "{}", msg), Self::NoValidConfigPath => write!(f, "No valid config path was found!"), Self::InvalidConfigPath(path, reason) => { - write!(f, "Failed to access {:?}: {}", path, reason) + write!(f, "Failed to access {path:?}: {reason}") } - Self::ConfigTooLarge(size) => write!(f, "The config file was too large ({} bytes)! Pass in --large-config to bypass this check.", size), + Self::ConfigTooLarge(size) => write!(f, "The config file was too large ({size} bytes)! Pass in --large-config to bypass this check."), Self::ZeroByteConfig => write!(f, "The config provided reported a size of 0 bytes. Please check your config path!"), Self::JsonParse(e) => e.fmt(f), } diff --git a/src/main.rs b/src/main.rs index 7b17525..b58ad93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,16 +9,19 @@ use crate::config::{ get_config_data, load_custom_path_config, read_config, ConfigData, Route, RouteGroup, }; -use actix_web::{middleware::Logger, App, HttpServer}; +use anyhow::Result; +use arc_swap::ArcSwap; +use axum::routing::get; +use axum::{Extension, Router}; use clap::Parser; use error::BunBunError; -use handlebars::{Handlebars, TemplateError}; +use handlebars::Handlebars; use hotwatch::{Event, Hotwatch}; -use log::{debug, error, info, trace, warn}; +use log::{debug, info, trace, warn}; use simple_logger::SimpleLogger; use std::cmp::min; use std::collections::HashMap; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; use std::time::Duration; mod cli; @@ -39,20 +42,9 @@ pub struct State { routes: HashMap, } -#[actix_web::main] +#[tokio::main] #[cfg(not(tarpaulin_include))] -async fn main() { - std::process::exit(match run().await { - Ok(_) => 0, - Err(e) => { - error!("{}", e); - 1 - } - }) -} - -#[cfg(not(tarpaulin_include))] -async fn run() -> Result<(), BunBunError> { +async fn main() -> Result<()> { let opts = cli::Opts::parse(); init_logger(opts.verbose, opts.quiet)?; @@ -63,7 +55,7 @@ async fn run() -> Result<(), BunBunError> { }?; let conf = read_config(conf_data.file.try_clone()?, opts.large_config)?; - let state = Arc::from(RwLock::new(State { + let state = Arc::from(ArcSwap::from_pointee(State { public_address: conf.public_address, default_route: conf.default_route, routes: cache_routes(&conf.groups), @@ -71,27 +63,19 @@ async fn run() -> Result<(), BunBunError> { })); // Cannot be named _ or Rust will immediately drop it. - let _watch = start_watch(Arc::clone(&state), conf_data, opts.large_config)?; + let _watch = start_watch(Arc::clone(&state), conf_data, opts.large_config); - HttpServer::new(move || { - let templates = match compile_templates() { - Ok(templates) => templates, - // This implies a template error, which should be a compile time error. If - // we reach here then the release is very broken. - Err(e) => unreachable!("Failed to compile templates: {}", e), - }; - App::new() - .data(Arc::clone(&state)) - .app_data(templates) - .wrap(Logger::default()) - .service(routes::hop) - .service(routes::list) - .service(routes::index) - .service(routes::opensearch) - }) - .bind(&conf.bind_address)? - .run() - .await?; + let app = Router::new() + .route("/", get(routes::index)) + .route("/bunbunsearch.xml", get(routes::opensearch)) + .route("/ls", get(routes::list)) + .route("/hop", get(routes::hop)) + .layer(Extension(compile_templates()?)) + .layer(Extension(state)); + + axum::Server::bind(&conf.bind_address.parse()?) + .serve(app.into_make_service()) + .await?; Ok(()) } @@ -100,10 +84,7 @@ async fn run() -> Result<(), BunBunError> { /// in. Usually, these values are mutually exclusive, that is, if the number of /// verbose flags is non-zero then the quiet flag is zero, and vice versa. #[cfg(not(tarpaulin_include))] -fn init_logger( - num_verbose_flags: u8, - num_quiet_flags: u8, -) -> Result<(), BunBunError> { +fn init_logger(num_verbose_flags: u8, num_quiet_flags: u8) -> Result<()> { let log_level = match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 { -2 => None, @@ -143,7 +124,7 @@ fn cache_routes(groups: &[RouteGroup]) -> HashMap { /// Returns an instance with all pre-generated templates included into the /// binary. This allows for users to have a portable binary without needed the /// templates at runtime. -fn compile_templates() -> Result, TemplateError> { +fn compile_templates() -> Result> { let mut handlebars = Handlebars::new(); handlebars.set_strict_mode(true); handlebars.register_partial("bunbun_version", env!("CARGO_PKG_VERSION"))?; @@ -176,10 +157,10 @@ fn compile_templates() -> Result, TemplateError> { /// watches. #[cfg(not(tarpaulin_include))] fn start_watch( - state: Arc>, + state: Arc>, config_data: ConfigData, large_config: bool, -) -> Result { +) -> Result { let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?; let ConfigData { path, mut file } = config_data; let watch_result = watch.watch(&path, move |e: Event| { @@ -193,33 +174,32 @@ fn start_watch( match e { Event::Write(_) | Event::Create(_) => { trace!("Grabbing writer lock on state..."); - let mut state = - state.write().expect("Failed to get write lock on state"); trace!("Obtained writer lock on state!"); match read_config( file.try_clone().expect("Failed to clone file handle"), large_config, ) { Ok(conf) => { - state.public_address = conf.public_address; - state.default_route = conf.default_route; - state.routes = cache_routes(&conf.groups); - state.groups = conf.groups; + state.store(Arc::new(State { + public_address: conf.public_address, + default_route: conf.default_route, + routes: cache_routes(&conf.groups), + groups: conf.groups, + })); info!("Successfully updated active state"); } - Err(e) => warn!("Failed to update config file: {}", e), + Err(e) => warn!("Failed to update config file: {e}"), } } - _ => debug!("Saw event {:#?} but ignored it", e), + _ => debug!("Saw event {e:#?} but ignored it"), } }); match watch_result { - Ok(_) => info!("Watcher is now watching {:?}", &path), - Err(e) => warn!( - "Couldn't watch {:?}: {}. Changes to this file won't be seen!", - &path, e - ), + Ok(_) => info!("Watcher is now watching {path:?}"), + Err(e) => { + warn!("Couldn't watch {path:?}: {e}. Changes to this file won't be seen!",) + } } Ok(watch) @@ -228,9 +208,10 @@ fn start_watch( #[cfg(test)] mod init_logger { use super::*; + use anyhow::Result; #[test] - fn defaults_to_warn() -> Result<(), BunBunError> { + fn defaults_to_warn() -> Result<()> { init_logger(0, 0)?; assert_eq!(log::max_level(), log::Level::Warn); Ok(()) @@ -242,7 +223,7 @@ mod init_logger { #[test] #[ignore] - fn caps_to_2_when_log_level_is_lt_2() -> Result<(), BunBunError> { + fn caps_to_2_when_log_level_is_lt_2() -> Result<()> { init_logger(0, 3)?; assert_eq!(log::max_level(), log::LevelFilter::Off); Ok(()) @@ -250,7 +231,7 @@ mod init_logger { #[test] #[ignore] - fn caps_to_3_when_log_level_is_gt_3() -> Result<(), BunBunError> { + fn caps_to_3_when_log_level_is_gt_3() -> Result<()> { init_logger(4, 0)?; assert_eq!(log::max_level(), log::Level::Trace); Ok(()) @@ -261,15 +242,14 @@ mod init_logger { mod cache_routes { use super::*; use std::iter::FromIterator; - use std::str::FromStr; fn generate_external_routes( - routes: &[(&str, &str)], + routes: &[(&'static str, &'static str)], ) -> HashMap { HashMap::from_iter( routes .into_iter() - .map(|kv| (kv.0.into(), Route::from_str(kv.1).unwrap())), + .map(|(key, value)| ((*key).to_owned(), Route::from(*value))), ) } diff --git a/src/routes.rs b/src/routes.rs index 3942d98..4fa0587 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,8 +1,11 @@ use crate::config::{Route as ConfigRoute, RouteType}; use crate::{template_args, BunBunError, Route, State}; -use actix_web::web::{Data, Query}; -use actix_web::{get, http::header}; -use actix_web::{HttpRequest, HttpResponse, Responder}; +use arc_swap::ArcSwap; +use axum::body::{boxed, Bytes, Full}; +use axum::extract::Query; +use axum::http::{header, StatusCode}; +use axum::response::{Html, IntoResponse, Response}; +use axum::Extension; use handlebars::Handlebars; use log::{debug, error}; use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; @@ -10,7 +13,7 @@ use serde::Deserialize; use std::collections::HashMap; use std::path::PathBuf; use std::process::Command; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; /// https://url.spec.whatwg.org/#fragment-percent-encode-set const FRAGMENT_ENCODE_SET: &AsciiSet = &CONTROLS @@ -24,71 +27,62 @@ const FRAGMENT_ENCODE_SET: &AsciiSet = &CONTROLS .add(b'#') // Interpreted as a hyperlink section target .add(b'\''); -type StateData = Data>>; - -#[get("/")] -pub async fn index(data: StateData, req: HttpRequest) -> impl Responder { - let data = data.read().unwrap(); - HttpResponse::Ok() - .set_header(header::CONTENT_TYPE, "text/html; charset=utf-8") - .body( - req - .app_data::() - .unwrap() - .render( - "index", - &template_args::hostname(data.public_address.clone()), - ) - .unwrap(), +pub async fn index( + Extension(data): Extension>>, + Extension(handlebars): Extension>, +) -> impl IntoResponse { + handlebars + .render( + "index", + &template_args::hostname(&data.load().public_address), ) + .map(Html) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) } -#[get("/bunbunsearch.xml")] -pub async fn opensearch(data: StateData, req: HttpRequest) -> impl Responder { - let data = data.read().unwrap(); - HttpResponse::Ok() - .header( - header::CONTENT_TYPE, - "application/opensearchdescription+xml", - ) - .body( - req - .app_data::() - .unwrap() - .render( - "opensearch", - &template_args::hostname(data.public_address.clone()), - ) - .unwrap(), +pub async fn opensearch( + Extension(data): Extension>>, + Extension(handlebars): Extension>, +) -> impl IntoResponse { + handlebars + .render( + "opensearch", + &template_args::hostname(&data.load().public_address), ) + .map(|body| { + ( + StatusCode::OK, + [( + header::CONTENT_TYPE, + "application/opensearchdescription+xml", + )], + body, + ) + }) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) } -#[get("/ls")] -pub async fn list(data: StateData, req: HttpRequest) -> impl Responder { - let data = data.read().unwrap(); - HttpResponse::Ok() - .set_header(header::CONTENT_TYPE, "text/html; charset=utf-8") - .body( - req - .app_data::() - .unwrap() - .render("list", &data.groups) - .unwrap(), - ) +pub async fn list( + Extension(data): Extension>>, + Extension(handlebars): Extension>, +) -> impl IntoResponse { + handlebars + .render("list", &data.load().groups) + .map(Html) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub struct SearchQuery { to: String, } -#[get("/hop")] pub async fn hop( - data: StateData, - req: HttpRequest, - query: Query, -) -> impl Responder { - let data = data.read().unwrap(); + Extension(data): Extension>>, + Extension(handlebars): Extension>, + Query(query): Query, +) -> impl IntoResponse { + let data = data.load(); match resolve_hop(&query.to, &data.routes, &data.default_route) { RouteResolution::Resolved { route: path, args } => { @@ -106,29 +100,36 @@ pub async fn hop( }; match resolved_template { - Ok(HopAction::Redirect(path)) => HttpResponse::Found() - .header( - header::LOCATION, - req - .app_data::() - .unwrap() + Ok(HopAction::Redirect(path)) => Response::builder() + .status(StatusCode::FOUND) + .header(header::LOCATION, &path) + .body(boxed(Full::from( + handlebars .render_template( - std::str::from_utf8(path.as_bytes()).unwrap(), - &template_args::query( - utf8_percent_encode(&args, FRAGMENT_ENCODE_SET).to_string(), - ), + &path, + &template_args::query(utf8_percent_encode( + &args, + FRAGMENT_ENCODE_SET, + )), ) .unwrap(), - ) - .finish(), - Ok(HopAction::Body(body)) => HttpResponse::Ok().body(body), + ))), + Ok(HopAction::Body(body)) => Response::builder() + .status(StatusCode::OK) + .body(boxed(Full::new(Bytes::from(body)))), Err(e) => { error!("Failed to redirect user for {}: {}", path, e); - HttpResponse::InternalServerError().body("Something went wrong :(\n") + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(boxed(Full::from("Something went wrong :(\n"))) } } + .unwrap() } - RouteResolution::Unresolved => HttpResponse::NotFound().body("not found"), + RouteResolution::Unresolved => Response::builder() + .status(StatusCode::NOT_FOUND) + .body(boxed(Full::from("not found\n"))) + .unwrap(), } } @@ -236,6 +237,7 @@ fn resolve_path(path: PathBuf, args: &str) -> Result { #[cfg(test)] mod resolve_hop { use super::*; + use anyhow::Result; use std::str::FromStr; fn generate_route_result<'a>( @@ -269,51 +271,45 @@ mod resolve_hop { } #[test] - fn only_default_routes_some_default_yields_default_hop() { + fn only_default_routes_some_default_yields_default_hop() -> Result<()> { let mut map: HashMap = HashMap::new(); - map.insert( - "google".into(), - Route::from_str("https://example.com").unwrap(), - ); + map.insert("google".into(), Route::from_str("https://example.com")?); assert_eq!( resolve_hop("hello world", &map, &Some(String::from("google"))), generate_route_result( - &Route::from_str("https://example.com").unwrap(), + &Route::from_str("https://example.com")?, "hello world" ), ); + Ok(()) } #[test] - fn non_default_routes_some_default_yields_non_default_hop() { + fn non_default_routes_some_default_yields_non_default_hop() -> Result<()> { let mut map: HashMap = HashMap::new(); - map.insert( - "google".into(), - Route::from_str("https://example.com").unwrap(), - ); + map.insert("google".into(), Route::from_str("https://example.com")?); assert_eq!( resolve_hop("google hello world", &map, &Some(String::from("a"))), generate_route_result( - &Route::from_str("https://example.com").unwrap(), + &Route::from_str("https://example.com")?, "hello world" ), ); + Ok(()) } #[test] - fn non_default_routes_no_default_yields_non_default_hop() { + fn non_default_routes_no_default_yields_non_default_hop() -> Result<()> { let mut map: HashMap = HashMap::new(); - map.insert( - "google".into(), - Route::from_str("https://example.com").unwrap(), - ); + map.insert("google".into(), Route::from_str("https://example.com")?); assert_eq!( resolve_hop("google hello world", &map, &None), generate_route_result( - &Route::from_str("https://example.com").unwrap(), + &Route::from_str("https://example.com")?, "hello world" ), ); + Ok(()) } } @@ -371,6 +367,7 @@ mod check_route { #[cfg(test)] mod resolve_path { use super::{resolve_path, HopAction}; + use anyhow::Result; use std::env::current_dir; use std::path::PathBuf; @@ -387,12 +384,13 @@ mod resolve_path { } #[test] - fn relative_path_returns_ok() { + fn relative_path_returns_ok() -> Result<()> { // How many ".." needed to get to / - let nest_level = current_dir().unwrap().ancestors().count() - 1; + let nest_level = current_dir()?.ancestors().count() - 1; let mut rel_path = PathBuf::from("../".repeat(nest_level)); rel_path.push("./bin/echo"); assert!(resolve_path(rel_path, r#"{"body": "a"}"#).is_ok()); + Ok(()) } #[test] @@ -414,18 +412,21 @@ mod resolve_path { } #[test] - fn return_body() { + fn return_body() -> Result<()> { assert_eq!( - resolve_path(PathBuf::from("/bin/echo"), r#"{"body": "a"}"#).unwrap(), + resolve_path(PathBuf::from("/bin/echo"), r#"{"body": "a"}"#)?, HopAction::Body("a".to_string()) ); + + Ok(()) } #[test] - fn return_redirect() { + fn return_redirect() -> Result<()> { assert_eq!( - resolve_path(PathBuf::from("/bin/echo"), r#"{"redirect": "a"}"#).unwrap(), + resolve_path(PathBuf::from("/bin/echo"), r#"{"redirect": "a"}"#)?, HopAction::Redirect("a".to_string()) ); + Ok(()) } } diff --git a/src/template_args.rs b/src/template_args.rs index 92b001b..d9b84fe 100644 --- a/src/template_args.rs +++ b/src/template_args.rs @@ -1,17 +1,22 @@ +use std::borrow::Cow; + +use percent_encoding::PercentEncode; use serde::Serialize; -pub fn query(query: String) -> impl Serialize { +pub fn query<'a>(query: PercentEncode<'a>) -> impl Serialize + 'a { #[derive(Serialize)] - struct TemplateArgs { - query: String, + struct TemplateArgs<'a> { + query: Cow<'a, str>, + } + TemplateArgs { + query: query.into(), } - TemplateArgs { query } } -pub fn hostname(hostname: String) -> impl Serialize { +pub fn hostname<'a>(hostname: &'a str) -> impl Serialize + 'a { #[derive(Serialize)] - pub struct TemplateArgs { - pub hostname: String, + pub struct TemplateArgs<'a> { + pub hostname: &'a str, } TemplateArgs { hostname } }