diff --git a/.cargo/audit.toml b/.cargo/audit.toml index b718ff211..2d2668d93 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -1,34 +1,16 @@ [advisories] ignore = [ - "RUSTSEC-2020-0016", # net2 crate has been deprecated; use socket2 instead - # https://github.com/rust-lang/docs.rs/issues/760 - "RUSTSEC-2020-0036", # failure is officially deprecated/unmaintained # https://github.com/rust-lang/docs.rs/issues/1014 - "RUSTSEC-2020-0056", # stdweb is unmaintained - # https://github.com/rust-lang/docs.rs/issues/1122 - "RUSTSEC-2020-0071", # `time` localtime_r segfault # https://github.com/rust-lang/docs.rs/issues/1523 "RUSTSEC-2020-0159", # `chrono` localtime_r segfault # https://github.com/rust-lang/docs.rs/issues/1525 - "RUSTSEC-2021-0078", # Lenient hyper header parsing of Content-Length could allow request smuggling - # https://github.com/rust-lang/docs.rs/issues/1460 - - "RUSTSEC-2021-0079", # Integer overflow in hyper's parsing of the Transfer-Encoding header leads to data loss - # https://github.com/rust-lang/docs.rs/issues/1459 - "RUSTSEC-2021-0127", # serde_cbor is unmaintained # https://github.com/rust-lang/docs.rs/issues/1568 - - "RUSTSEC-2021-0144", # traitobject is Unmaintained - # https://github.com/rust-lang/docs.rs/issues/1826 - - "RUSTSEC-2019-0039", # typemap is Unmaintained - # https://github.com/rust-lang/docs.rs/issues/1827 ] informational_warnings = ["unmaintained"] # warn for categories of informational advisories severity_threshold = "low" # CVSS severity ("none", "low", "medium", "high", "critical") diff --git a/Cargo.lock b/Cargo.lock index dc5c9cda5..cab3bdb5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom 0.2.8", "once_cell", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -37,7 +37,7 @@ dependencies = [ "cfg-if", "getrandom 0.2.8", "once_cell", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -134,10 +134,10 @@ checksum = "fdb8867f378f33f78a811a8eb9bf108ad99430d7aad43315dd9319c827ef6247" dependencies = [ "flate2", "http", - "log 0.4.17", + "log", "native-tls", "openssl", - "url 2.3.1", + "url", "wildmatch", ] @@ -152,15 +152,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -186,7 +177,7 @@ dependencies = [ "bytes", "hex", "http", - "hyper 0.14.23", + "hyper", "ring", "time 0.3.17", "tokio", @@ -222,7 +213,7 @@ dependencies = [ "http", "http-body", "lazy_static", - "percent-encoding 2.2.0", + "percent-encoding", "pin-project-lite", "tracing", ] @@ -348,7 +339,7 @@ dependencies = [ "hex", "http", "once_cell", - "percent-encoding 2.2.0", + "percent-encoding", "regex", "ring", "time 0.3.17", @@ -403,7 +394,7 @@ dependencies = [ "fastrand", "http", "http-body", - "hyper 0.14.23", + "hyper", "hyper-rustls", "lazy_static", "pin-project-lite", @@ -437,9 +428,9 @@ dependencies = [ "futures-core", "http", "http-body", - "hyper 0.14.23", + "hyper", "once_cell", - "percent-encoding 2.2.0", + "percent-encoding", "pin-project-lite", "pin-utils", "tokio", @@ -557,12 +548,12 @@ dependencies = [ "headers", "http", "http-body", - "hyper 0.14.23", + "hyper", "itoa 1.0.4", "matchit", "memchr", - "mime 0.3.16", - "percent-encoding 2.2.0", + "mime", + "percent-encoding", "pin-project-lite", "rustversion", "serde", @@ -588,7 +579,7 @@ dependencies = [ "futures-util", "http", "http-body", - "mime 0.3.16", + "mime", "rustversion", "tower-layer", "tower-service", @@ -604,7 +595,7 @@ dependencies = [ "bytes", "futures-util", "http", - "mime 0.3.16", + "mime", "pin-project-lite", "tokio", "tower", @@ -628,16 +619,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" -dependencies = [ - "byteorder", - "safemem", -] - [[package]] name = "base64" version = "0.13.1" @@ -934,15 +915,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "clru" version = "0.5.0" @@ -1176,7 +1148,7 @@ version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if", "crossbeam-utils", "memoffset 0.7.1", @@ -1436,18 +1408,18 @@ dependencies = [ "hostname", "http", "httpdate", - "hyper 0.14.23", + "hyper", "indoc", - "iron", "kuchiki", - "log 0.4.17", + "log", "lol_html", "memmap2", - "mime 0.3.16", - "mime_guess 2.0.4", + "mime", + "mime_guess", "mockito", "once_cell", "path-slash", + "percent-encoding", "postgres", "postgres-types", "procfs", @@ -1458,7 +1430,6 @@ dependencies = [ "rayon", "regex", "reqwest", - "router", "rustwide", "schemamama", "schemamama_postgres", @@ -1482,7 +1453,6 @@ dependencies = [ "test-case", "thiserror", "thread_local", - "time 0.1.45", "time 0.3.17", "tokio", "toml", @@ -1492,7 +1462,7 @@ dependencies = [ "tracing", "tracing-log", "tracing-subscriber", - "url 2.3.1", + "url", "uuid", "walkdir", "zip", @@ -1679,7 +1649,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "percent-encoding 2.2.0", + "percent-encoding", ] [[package]] @@ -1692,12 +1662,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futf" version = "0.1.5" @@ -1786,7 +1750,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -2244,7 +2208,7 @@ dependencies = [ "git-url", "git-validate", "git-worktree", - "log 0.4.17", + "log", "once_cell", "signal-hook", "smallvec", @@ -2332,7 +2296,7 @@ dependencies = [ "git-path", "home", "thiserror", - "url 2.3.1", + "url", ] [[package]] @@ -2372,10 +2336,10 @@ dependencies = [ "bitflags", "libc", "libgit2-sys", - "log 0.4.17", + "log", "openssl-probe", "openssl-sys", - "url 2.3.1", + "url", ] [[package]] @@ -2387,7 +2351,7 @@ dependencies = [ "aho-corasick", "bstr 0.2.17", "fnv", - "log 0.4.17", + "log", "regex", ] @@ -2489,7 +2453,7 @@ dependencies = [ "headers-core", "http", "httpdate", - "mime 0.3.16", + "mime", "sha1", ] @@ -2570,7 +2534,7 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5c13fb08e5d4dfc151ee5e88bae63f7773d61852f3bdc73c9f4b9e1bde03148" dependencies = [ - "log 0.4.17", + "log", "mac", "markup5ever", "proc-macro2", @@ -2630,25 +2594,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" -[[package]] -name = "hyper" -version = "0.10.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" -dependencies = [ - "base64 0.9.3", - "httparse", - "language-tags", - "log 0.3.9", - "mime 0.2.6", - "num_cpus", - "time 0.1.45", - "traitobject", - "typeable", - "unicase 1.4.2", - "url 1.7.2", -] - [[package]] name = "hyper" version = "0.14.23" @@ -2680,8 +2625,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ "http", - "hyper 0.14.23", - "log 0.4.17", + "hyper", + "log", "rustls", "rustls-native-certs", "tokio", @@ -2695,7 +2640,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.23", + "hyper", "native-tls", "tokio", "tokio-native-tls", @@ -2725,17 +2670,6 @@ dependencies = [ "cxx-build", ] -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.3.0" @@ -2755,7 +2689,7 @@ dependencies = [ "crossbeam-utils", "globset", "lazy_static", - "log 0.4.17", + "log", "memchr", "regex", "same-file", @@ -2780,7 +2714,7 @@ version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown 0.12.3", ] @@ -2831,22 +2765,6 @@ version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" -[[package]] -name = "iron" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6d308ca2d884650a8bf9ed2ff4cb13fbb2207b71f64cda11dc9b892067295e8" -dependencies = [ - "hyper 0.10.16", - "log 0.3.9", - "mime_guess 1.8.8", - "modifier", - "num_cpus", - "plugin", - "typemap", - "url 1.7.2", -] - [[package]] name = "is-terminal" version = "0.4.1" @@ -2920,12 +2838,6 @@ dependencies = [ "selectors", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lasso" version = "0.5.1" @@ -3027,19 +2939,10 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.17", -] - [[package]] name = "log" version = "0.4.17" @@ -3080,7 +2983,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a24f40fb03852d1cdd84330cddcaf98e9ec08a7b7768e952fad3b4cf048ec8fd" dependencies = [ - "log 0.4.17", + "log", "phf 0.8.0", "phf_codegen 0.8.0", "string_cache", @@ -3156,7 +3059,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -3165,16 +3068,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ - "autocfg 1.1.0", -] - -[[package]] -name = "mime" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -dependencies = [ - "log 0.3.9", + "autocfg", ] [[package]] @@ -3183,26 +3077,14 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "1.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216929a5ee4dd316b1702eedf5e74548c123d370f47841ceaac38ca154690ca3" -dependencies = [ - "mime 0.2.6", - "phf 0.7.24", - "phf_codegen 0.7.24", - "unicase 1.4.2", -] - [[package]] name = "mime_guess" version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" dependencies = [ - "mime 0.3.16", - "unicase 2.6.0", + "mime", + "unicase", ] [[package]] @@ -3236,7 +3118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", - "log 0.4.17", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.42.0", ] @@ -3251,7 +3133,7 @@ dependencies = [ "colored", "httparse", "lazy_static", - "log 0.4.17", + "log", "rand 0.8.5", "regex", "serde_json", @@ -3259,12 +3141,6 @@ dependencies = [ "similar", ] -[[package]] -name = "modifier" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" - [[package]] name = "native-tls" version = "0.2.11" @@ -3273,7 +3149,7 @@ checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", - "log 0.4.17", + "log", "openssl", "openssl-probe", "openssl-sys", @@ -3295,7 +3171,7 @@ version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bitflags", "cfg-if", "libc", @@ -3335,7 +3211,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -3346,7 +3222,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -3356,7 +3232,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -3368,7 +3244,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -3483,7 +3359,7 @@ version = "0.9.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "openssl-src", @@ -3497,7 +3373,7 @@ version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4750134fb6a5d49afc80777394ad5d95b04bc12068c6abb92fae8f43817270f" dependencies = [ - "log 0.4.17", + "log", "serde", "winapi", ] @@ -3561,12 +3437,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" - [[package]] name = "percent-encoding" version = "2.2.0" @@ -3617,15 +3487,6 @@ dependencies = [ "sha1", ] -[[package]] -name = "phf" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" -dependencies = [ - "phf_shared 0.7.24", -] - [[package]] name = "phf" version = "0.8.0" @@ -3657,16 +3518,6 @@ dependencies = [ "phf_shared 0.11.1", ] -[[package]] -name = "phf_codegen" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" -dependencies = [ - "phf_generator 0.7.24", - "phf_shared 0.7.24", -] - [[package]] name = "phf_codegen" version = "0.8.0" @@ -3687,16 +3538,6 @@ dependencies = [ "phf_shared 0.11.1", ] -[[package]] -name = "phf_generator" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" -dependencies = [ - "phf_shared 0.7.24", - "rand 0.6.5", -] - [[package]] name = "phf_generator" version = "0.8.0" @@ -3765,23 +3606,13 @@ dependencies = [ "syn", ] -[[package]] -name = "phf_shared" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" -dependencies = [ - "siphasher 0.2.3", - "unicase 1.4.2", -] - [[package]] name = "phf_shared" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" dependencies = [ - "siphasher 0.3.10", + "siphasher", ] [[package]] @@ -3790,7 +3621,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a68318426de33640f02be62b4ae8eb1261be2efbc337b60c54d845bf4484e0d9" dependencies = [ - "siphasher 0.3.10", + "siphasher", ] [[package]] @@ -3799,7 +3630,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ - "siphasher 0.3.10", + "siphasher", ] [[package]] @@ -3808,7 +3639,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" dependencies = [ - "siphasher 0.3.10", + "siphasher", "uncased", ] @@ -3878,15 +3709,6 @@ dependencies = [ "plotters-backend", ] -[[package]] -name = "plugin" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" -dependencies = [ - "typemap", -] - [[package]] name = "postgres" version = "0.19.4" @@ -3896,7 +3718,7 @@ dependencies = [ "bytes", "fallible-iterator", "futures-util", - "log 0.4.17", + "log", "tokio", "tokio-postgres", ] @@ -3979,7 +3801,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -3990,7 +3812,7 @@ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -4068,7 +3890,7 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" dependencies = [ - "log 0.4.17", + "log", "parking_lot", "scheduled-thread-pool", ] @@ -4083,25 +3905,6 @@ dependencies = [ "r2d2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg 0.1.2", - "rand_xorshift", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -4112,8 +3915,8 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", - "rand_pcg 0.2.1", + "rand_hc", + "rand_pcg", ] [[package]] @@ -4127,16 +3930,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -4157,21 +3950,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -4190,15 +3968,6 @@ dependencies = [ "getrandom 0.2.8", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -4208,50 +3977,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - [[package]] name = "rand_pcg" version = "0.2.1" @@ -4261,15 +3986,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rayon" version = "1.6.1" @@ -4292,15 +4008,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -4363,7 +4070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "882f368737489ea543bc5c340e6f3d34a28c39980bd9a979e47322b26f60ac40" dependencies = [ "libc", - "log 0.4.17", + "log", "num_cpus", "rayon", "winapi", @@ -4383,15 +4090,15 @@ dependencies = [ "h2", "http", "http-body", - "hyper 0.14.23", + "hyper", "hyper-tls", "ipnet", "js-sys", - "log 0.4.17", - "mime 0.3.16", + "log", + "mime", "native-tls", "once_cell", - "percent-encoding 2.2.0", + "percent-encoding", "pin-project-lite", "serde", "serde_json", @@ -4399,7 +4106,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tower-service", - "url 2.3.1", + "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -4421,23 +4128,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "route-recognizer" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea509065eb0b3c446acdd0102f0d46567dc30902dc0be91d6552035d92b0f4f8" - -[[package]] -name = "router" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc63b6f3b8895b0d04e816b2b1aa58fdba2d5acca3cbb8f0ab8e017347d57397" -dependencies = [ - "iron", - "route-recognizer", - "url 1.7.2", -] - [[package]] name = "roxmltree" version = "0.14.1" @@ -4502,7 +4192,7 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" dependencies = [ - "log 0.4.17", + "log", "ring", "sct", "webpki", @@ -4551,9 +4241,9 @@ dependencies = [ "git2", "http", "lazy_static", - "log 0.4.17", + "log", "nix", - "percent-encoding 2.2.0", + "percent-encoding", "remove_dir_all 0.7.0", "scopeguard", "serde", @@ -4614,7 +4304,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f726d3b10198a91b545c12e55775ddf4abb681056aa62adf75ed00b68855ef9" dependencies = [ - "log 0.4.17", + "log", ] [[package]] @@ -4682,7 +4372,7 @@ dependencies = [ "cssparser", "derive_more", "fxhash", - "log 0.4.17", + "log", "matches", "phf 0.8.0", "phf_codegen 0.8.0", @@ -4789,7 +4479,7 @@ dependencies = [ "sentry-core", "tower-layer", "tower-service", - "url 2.3.1", + "url", ] [[package]] @@ -4816,7 +4506,7 @@ dependencies = [ "serde_json", "thiserror", "time 0.3.17", - "url 2.3.1", + "url", "uuid", ] @@ -4964,12 +4654,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" - [[package]] name = "siphasher" version = "0.3.10" @@ -4982,7 +4666,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -5006,10 +4690,10 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" dependencies = [ - "autocfg 1.1.0", + "autocfg", "serde", "static_assertions", - "version_check 0.9.4", + "version_check", ] [[package]] @@ -5222,7 +4906,7 @@ dependencies = [ "globwalk", "humansize", "lazy_static", - "percent-encoding 2.2.0", + "percent-encoding", "pest", "pest_derive", "rand 0.8.5", @@ -5376,7 +5060,7 @@ version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bytes", "libc", "memchr", @@ -5422,9 +5106,9 @@ dependencies = [ "fallible-iterator", "futures-channel", "futures-util", - "log 0.4.17", + "log", "parking_lot", - "percent-encoding 2.2.0", + "percent-encoding", "phf 0.11.1", "pin-project-lite", "postgres-protocol", @@ -5534,7 +5218,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", - "log 0.4.17", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5568,7 +5252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ "lazy_static", - "log 0.4.17", + "log", "tracing-core", ] @@ -5588,39 +5272,18 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "traitobject" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" - [[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "typeable" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" - [[package]] name = "typed-arena" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" -[[package]] -name = "typemap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" -dependencies = [ - "unsafe-any", -] - [[package]] name = "typenum" version = "1.16.0" @@ -5657,7 +5320,7 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" dependencies = [ - "version_check 0.9.4", + "version_check", ] [[package]] @@ -5710,22 +5373,13 @@ dependencies = [ "unic-common", ] -[[package]] -name = "unicase" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" -dependencies = [ - "version_check 0.1.5", -] - [[package]] name = "unicase" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "version_check 0.9.4", + "version_check", ] [[package]] @@ -5773,15 +5427,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" -[[package]] -name = "unsafe-any" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" -dependencies = [ - "traitobject", -] - [[package]] name = "untrusted" version = "0.7.1" @@ -5796,21 +5441,10 @@ checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f" dependencies = [ "base64 0.13.1", "chunked_transfer", - "log 0.4.17", + "log", "native-tls", "once_cell", - "url 2.3.1", -] - -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -dependencies = [ - "idna 0.1.5", - "matches", - "percent-encoding 1.0.1", + "url", ] [[package]] @@ -5820,8 +5454,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", - "idna 0.3.0", - "percent-encoding 2.2.0", + "idna", + "percent-encoding", "serde", ] @@ -5865,12 +5499,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" - [[package]] name = "version_check" version = "0.9.4" @@ -5894,7 +5522,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log 0.4.17", + "log", "try-lock", ] @@ -5933,7 +5561,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", - "log 0.4.17", + "log", "once_cell", "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index f3d331742..9e66afb57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,6 @@ semver = { version = "1.0.4", features = ["serde"] } slug = "0.1.1" r2d2 = "0.8" r2d2_postgres = "0.18" -# iron needs url@1, but it reexports it as iron::url, so we can start using -# url@2 for other usecases url = { version = "2.1.1", features = ["serde"] } docsrs-metadata = { path = "crates/metadata" } anyhow = { version = "1.0.42", features = ["backtrace"]} @@ -72,7 +70,7 @@ serde_cbor = "0.11.1" getrandom = "0.2.1" # Async -tokio = { version = "1.0", features = ["rt-multi-thread"] } +tokio = { version = "1.0", features = ["rt-multi-thread", "signal", "macros"] } futures-util = "0.3.5" aws-config = "0.51.0" aws-sdk-s3 = "0.21.0" @@ -86,13 +84,10 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" memmap2 = "0.5.0" -# iron dependencies -iron = "0.6" -router = "0.6" - # axum dependencies axum = { version = "0.6.1", features = ["headers"]} axum-extra = "0.4.2" +percent-encoding = "2.2.0" hyper = { version = "0.14.15", default-features = false } tower = "0.4.11" tower-service = "0.3.2" @@ -109,7 +104,6 @@ walkdir = "2" # Date and Time utilities chrono = { version = "0.4.11", features = ["serde"] } -time = "0.1" # TODO: Remove once `iron` is removed # Transitive dependencies we don't use directly but need to have specific versions of thread_local = "1.1.3" @@ -131,7 +125,6 @@ test-case = "2.0.0" fn-error-context = "0.2.0" aws-smithy-client = { version = "0.51.0", features = ["test-util"]} aws-smithy-http = "0.51.0" -tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } indoc = "1.0.7" [build-dependencies] diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 3fd4a7f26..73ff0b6f6 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -22,6 +22,7 @@ use std::{ sync::Arc, }; use tokio::runtime::Runtime; +use tracing::{instrument, trace}; const MAX_CONCURRENT_UPLOADS: usize = 1000; @@ -162,23 +163,27 @@ impl Storage { } } + #[instrument(skip(fetch_time))] pub(crate) fn fetch_rustdoc_file( &self, name: &str, version: &str, path: &str, archive_storage: bool, - fetch_time: &mut RenderingTimesRecorder, + fetch_time: Option<&mut RenderingTimesRecorder>, ) -> Result { + trace!("fetch rustdoc file"); Ok(if archive_storage { self.get_from_archive( &rustdoc_archive_path(name, version), path, self.max_file_size_for(path), - Some(fetch_time), + fetch_time, )? } else { - fetch_time.step("fetch from storage"); + if let Some(fetch_time) = fetch_time { + fetch_time.step("fetch from storage"); + } // Add rustdoc prefix, name and version to the path for accessing the file stored in the database let remote_path = format!("rustdoc/{}/{}/{}", name, version, path); self.get(&remote_path, self.max_file_size_for(path))? diff --git a/src/test/mod.rs b/src/test/mod.rs index 3525deafa..1bf90f52c 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -6,13 +6,10 @@ use crate::db::{Pool, PoolClient}; use crate::error::Result; use crate::repositories::RepositoryStatsUpdater; use crate::storage::{Storage, StorageKind}; -use crate::web::{ - build_axum_app, build_strangler_service, cache, page::TemplateData, start_iron_server, -}; +use crate::web::{build_axum_app, cache, page::TemplateData}; use crate::{BuildQueue, Config, Context, Index, Metrics}; use anyhow::Context as _; use fn_error_context::context; -use iron::{headers::CacheControl, Listening}; use once_cell::unsync::OnceCell; use postgres::Client as Connection; use reqwest::{ @@ -61,7 +58,7 @@ pub(crate) fn assert_no_cache(res: &Response) { res.headers() .get("Cache-Control") .expect("missing cache-control header"), - cache::NO_CACHE, + cache::NO_CACHING, ); } @@ -74,14 +71,13 @@ pub(crate) fn assert_cache_control( assert!(config.cache_control_stale_while_revalidate.is_some()); let cache_control = res.headers().get("Cache-Control"); - let expected_directives = cache_policy.render(config); - if expected_directives.is_empty() { - assert!(cache_control.is_none()); - } else { + if let Some(expected_directives) = cache_policy.render(config) { assert_eq!( cache_control.expect("missing cache-control header"), - &CacheControl(expected_directives).to_string() + expected_directives, ); + } else { + assert!(cache_control.is_none()); } } @@ -101,9 +97,9 @@ pub(crate) fn assert_success_cached( config: &Config, ) -> Result<()> { let response = web.get(path).send()?; - assert_cache_control(&response, cache_policy, config); let status = response.status(); assert!(status.is_success(), "failed to GET {}: {}", path, status); + assert_cache_control(&response, cache_policy, config); Ok(()) } @@ -538,7 +534,6 @@ impl Drop for TestDatabase { } pub(crate) struct TestFrontend { - iron_server: Listening, axum_server_thread: JoinHandle<()>, axum_server_shutdown_signal: Sender<()>, axum_server_address: SocketAddr, @@ -563,10 +558,6 @@ impl TestFrontend { let template_data = Arc::new(TemplateData::new(&mut context.pool().unwrap().get().unwrap()).unwrap()); - debug!("starting iron server"); - let iron_server = start_iron_server(context, template_data.clone(), Some(1)) - .expect("could not start iron server"); - debug!("binding local TCP port for axum"); let axum_listener = TcpListener::bind("127.0.0.1:0".parse::().unwrap()).unwrap(); @@ -585,14 +576,7 @@ impl TestFrontend { runtime.block_on(async { axum::Server::from_tcp(axum_listener) .unwrap() - .serve( - axum_app - .fallback_service( - build_strangler_service(iron_server.socket) - .expect("could not build strangler service"), - ) - .into_make_service(), - ) + .serve(axum_app.into_make_service()) .with_graceful_shutdown(async { rx.await.ok(); }) @@ -603,7 +587,6 @@ impl TestFrontend { }); Self { - iron_server, axum_server_address: axum_addr, axum_server_thread: handle, axum_server_shutdown_signal: tx, @@ -623,16 +606,6 @@ impl TestFrontend { self.axum_server_thread .join() .expect("could not join axum background thread"); - - trace!("forgetting about iron"); - // Iron is bugged, and it never closes the server even when the listener is dropped. To - // avoid never-ending tests this method forgets about the server, leaking it and allowing the - // program to end. - // - // The OS will then close all the dangling servers once the process exits. - // - // https://docs.rs/iron/0.5/iron/struct.Listening.html#method.close - std::mem::forget(self.iron_server); } fn build_url(&self, url: &str) -> String { diff --git a/src/web/cache.rs b/src/web/cache.rs index e12b59e9c..dede7dead 100644 --- a/src/web/cache.rs +++ b/src/web/cache.rs @@ -1,19 +1,19 @@ -use super::STATIC_FILE_CACHE_DURATION; use crate::config::Config; use axum::{ http::Request as AxumHttpRequest, middleware::Next, response::Response as AxumResponse, }; -use http::header::CACHE_CONTROL; -use iron::{ - headers::{CacheControl, CacheDirective}, - AfterMiddleware, IronResult, Request, Response, -}; +use http::{header::CACHE_CONTROL, HeaderValue}; use std::sync::Arc; -#[cfg(test)] -pub const NO_CACHE: &str = "max-age=0"; +pub static NO_CACHING: HeaderValue = HeaderValue::from_static("max-age=0"); + +pub static NO_STORE_MUST_REVALIDATE: HeaderValue = + HeaderValue::from_static("no-cache, no-store, must-revalidate, max-age=0"); + +pub static FOREVER_IN_CDN_AND_BROWSER: HeaderValue = HeaderValue::from_static("max-age=31104000"); /// defines the wanted caching behaviour for a web response. +#[derive(Debug)] pub enum CachePolicy { /// no browser or CDN caching. /// In some cases the browser might still use cached content, @@ -42,81 +42,26 @@ pub enum CachePolicy { } impl CachePolicy { - pub fn render(&self, config: &Config) -> Vec { + pub fn render(&self, config: &Config) -> Option { match *self { - CachePolicy::NoCaching => { - vec![CacheDirective::MaxAge(0)] - } - CachePolicy::NoStoreMustRevalidate => { - vec![ - CacheDirective::NoCache, - CacheDirective::NoStore, - CacheDirective::MustRevalidate, - CacheDirective::MaxAge(0), - ] - } - CachePolicy::ForeverInCdnAndBrowser => { - vec![CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32)] - } + CachePolicy::NoCaching => Some(NO_CACHING.clone()), + CachePolicy::NoStoreMustRevalidate => Some(NO_STORE_MUST_REVALIDATE.clone()), + CachePolicy::ForeverInCdnAndBrowser => Some(FOREVER_IN_CDN_AND_BROWSER.clone()), CachePolicy::ForeverInCdn => { // A missing `max-age` or `s-maxage` in the Cache-Control header will lead to // CloudFront using the default TTL, while the browser not seeing any caching header. // This means we can have the CDN caching the documentation while just // issuing a purge after a build. // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist - vec![] - } - CachePolicy::ForeverInCdnAndStaleInBrowser => { - let mut directives = CachePolicy::ForeverInCdn.render(config); - if let Some(seconds) = config.cache_control_stale_while_revalidate { - directives.push(CacheDirective::Extension( - "stale-while-revalidate".to_string(), - Some(seconds.to_string()), - )); - } - directives + None } + CachePolicy::ForeverInCdnAndStaleInBrowser => config + .cache_control_stale_while_revalidate + .map(|seconds| format!("stale-while-revalidate={seconds}").parse().unwrap()), } } } -impl iron::typemap::Key for CachePolicy { - type Value = CachePolicy; -} - -/// Middleware to ensure a correct cache-control header. -/// The default is an explicit "never cache" header, which -/// can be adapted via: -/// ```ignore -/// resp.extensions.insert::(CachePolicy::ForeverInCdn); -/// # change Cache::ForeverInCdn into the cache polity you want to have -/// ``` -/// in a handler function. -pub(super) struct CacheMiddleware; - -impl AfterMiddleware for CacheMiddleware { - fn after(&self, req: &mut Request, mut res: Response) -> IronResult { - let config = req.extensions.get::().expect("missing config"); - let cache = res - .extensions - .get::() - .unwrap_or(&CachePolicy::NoCaching); - - if cfg!(test) { - assert!( - !res.headers.has::(), - "handlers should never set their own caching headers and only use CachePolicy to control caching." - ); - } - - let directives = cache.render(config); - if !directives.is_empty() { - res.headers.set(CacheControl(directives)) - } - Ok(res) - } -} - pub(crate) async fn cache_middleware(req: AxumHttpRequest, next: Next) -> AxumResponse { let config = req .extensions() @@ -138,15 +83,10 @@ pub(crate) async fn cache_middleware(req: AxumHttpRequest, next: Next) ); } - let directives = cache.render(&config); - if !directives.is_empty() { - response.headers_mut().insert( - CACHE_CONTROL, - CacheControl(directives) - .to_string() - .parse() - .expect("cache-control header could not be parsed"), - ); + if let Some(cache_directive) = cache.render(&config) { + response + .headers_mut() + .insert(CACHE_CONTROL, cache_directive); } response } @@ -155,25 +95,24 @@ pub(crate) async fn cache_middleware(req: AxumHttpRequest, next: Next) mod tests { use super::*; use crate::test::wrapper; - use iron::headers::CacheControl; use test_case::test_case; - #[test_case(CachePolicy::NoCaching, "max-age=0")] + #[test_case(CachePolicy::NoCaching, Some("max-age=0"))] #[test_case( CachePolicy::NoStoreMustRevalidate, - "no-cache, no-store, must-revalidate, max-age=0" + Some("no-cache, no-store, must-revalidate, max-age=0") )] - #[test_case(CachePolicy::ForeverInCdnAndBrowser, "max-age=31104000")] - #[test_case(CachePolicy::ForeverInCdn, "")] + #[test_case(CachePolicy::ForeverInCdnAndBrowser, Some("max-age=31104000"))] + #[test_case(CachePolicy::ForeverInCdn, None)] #[test_case( CachePolicy::ForeverInCdnAndStaleInBrowser, - "stale-while-revalidate=86400" + Some("stale-while-revalidate=86400") )] - fn render(cache: CachePolicy, expected: &str) { + fn render(cache: CachePolicy, expected: Option<&str>) { wrapper(|env| { assert_eq!( - CacheControl(cache.render(&env.config())).to_string(), - expected + cache.render(&env.config()), + expected.map(|s| HeaderValue::from_str(s).unwrap()) ); Ok(()) }); @@ -184,11 +123,9 @@ mod tests { wrapper(|env| { env.override_config(|config| config.cache_control_stale_while_revalidate = None); - assert_eq!( - CacheControl(CachePolicy::ForeverInCdnAndStaleInBrowser.render(&env.config())) - .to_string(), - "" - ); + assert!(CachePolicy::ForeverInCdnAndStaleInBrowser + .render(&env.config()) + .is_none()); Ok(()) }); } @@ -200,8 +137,9 @@ mod tests { }); assert_eq!( - CacheControl(CachePolicy::ForeverInCdnAndStaleInBrowser.render(&env.config())) - .to_string(), + CachePolicy::ForeverInCdnAndStaleInBrowser + .render(&env.config()) + .unwrap(), "stale-while-revalidate=666" ); Ok(()) diff --git a/src/web/csp.rs b/src/web/csp.rs index b53590c46..47a4f5c74 100644 --- a/src/web/csp.rs +++ b/src/web/csp.rs @@ -2,12 +2,17 @@ use crate::config::Config; use axum::{ http::Request as AxumHttpRequest, middleware::Next, response::Response as AxumResponse, }; -use iron::{AfterMiddleware, BeforeMiddleware, IronResult, Request, Response}; -use std::{fmt::Write, sync::Arc}; +use std::{ + fmt::Write, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, +}; -pub(super) struct Csp { +pub(crate) struct Csp { nonce: String, - suppress: bool, + suppress: AtomicBool, } impl Csp { @@ -19,12 +24,12 @@ impl Csp { Self { nonce: base64::encode(random), - suppress: false, + suppress: AtomicBool::new(false), } } - pub(super) fn suppress(&mut self, suppress: bool) { - self.suppress = suppress; + pub(super) fn suppress(&self, suppress: bool) { + self.suppress.store(suppress, Ordering::Relaxed); } pub(super) fn nonce(&self) -> &str { @@ -32,7 +37,7 @@ impl Csp { } fn render(&self, content_type: ContentType) -> Option { - if self.suppress { + if self.suppress.load(Ordering::Relaxed) { return None; } let mut result = String::new(); @@ -83,63 +88,12 @@ impl Csp { } } -impl iron::typemap::Key for Csp { - type Value = Csp; -} - enum ContentType { Html, Svg, Other, } -pub(super) struct CspMiddleware; - -impl BeforeMiddleware for CspMiddleware { - fn before(&self, req: &mut Request) -> IronResult<()> { - req.extensions.insert::(Csp::new()); - Ok(()) - } -} - -impl AfterMiddleware for CspMiddleware { - fn after(&self, req: &mut Request, mut res: Response) -> IronResult { - let config = req - .extensions - .get::() - .expect("missing Config") - .clone(); - let csp = req.extensions.get_mut::().expect("missing CSP"); - - let content_type = res - .headers - .get_raw("Content-Type") - .and_then(|headers| headers.get(0)) - .map(|header| header.as_slice()); - - let preset = match content_type { - Some(b"text/html; charset=utf-8") => ContentType::Html, - Some(b"text/svg+xml") => ContentType::Svg, - _ => ContentType::Other, - }; - - if let Some(rendered) = csp.render(preset) { - res.headers.set_raw( - // The Report-Only header tells the browser to just log CSP failures instead of - // actually enforcing them. This is useful to check if the CSP works without - // impacting production traffic. - if config.csp_report_only { - "Content-Security-Policy-Report-Only" - } else { - "Content-Security-Policy" - }, - vec![rendered.as_bytes().to_vec()], - ); - } - Ok(res) - } -} - pub(crate) async fn csp_middleware(mut req: AxumHttpRequest, next: Next) -> AxumResponse { let csp_report_only = req .extensions() @@ -199,7 +153,7 @@ mod tests { #[test] fn test_csp_suppressed() { - let mut csp = Csp::new(); + let csp = Csp::new(); csp.suppress(true); assert!(csp.render(ContentType::Other).is_none()); diff --git a/src/web/error.rs b/src/web/error.rs index b3bcf8f64..1137e9548 100644 --- a/src/web/error.rs +++ b/src/web/error.rs @@ -1,116 +1,10 @@ use std::borrow::Cow; -use crate::{ - db::PoolError, - web::{page::WebPage, releases::Search, AxumErrorPage, ErrorPage}, -}; +use crate::web::{releases::Search, AxumErrorPage}; use axum::{ http::StatusCode, response::{IntoResponse, Response as AxumResponse}, }; -use iron::{status::Status, Handler, IronError, IronResult, Request, Response}; - -#[derive(Debug, Copy, Clone, thiserror::Error)] -pub enum Nope { - #[error("Requested resource not found")] - ResourceNotFound, - #[error("Requested build not found")] - BuildNotFound, - #[error("Requested crate not found")] - CrateNotFound, - #[error("Requested owner not found")] - OwnerNotFound, - #[error("Requested crate does not have specified version")] - VersionNotFound, - #[error("Internal server error")] - InternalServerError, -} - -impl From for IronError { - fn from(err: Nope) -> IronError { - use iron::status; - - let status = match err { - Nope::ResourceNotFound - | Nope::BuildNotFound - | Nope::CrateNotFound - | Nope::OwnerNotFound - | Nope::VersionNotFound => status::NotFound, - Nope::InternalServerError => status::InternalServerError, - }; - - IronError::new(err, status) - } -} - -impl Handler for Nope { - fn handle(&self, req: &mut Request) -> IronResult { - match self { - Nope::ResourceNotFound => { - // user tried to navigate to a resource (doc page/file) that doesn't exist - // TODO: Display the attempted page - ErrorPage { - title: "The requested resource does not exist", - message: Some("no such resource".into()), - status: Status::NotFound, - } - .into_response(req) - } - - Nope::BuildNotFound => ErrorPage { - title: "The requested build does not exist", - message: Some("no such build".into()), - status: Status::NotFound, - } - .into_response(req), - - Nope::CrateNotFound => { - // user tried to navigate to a crate that doesn't exist - // TODO: Display the attempted crate and a link to a search for said crate - ErrorPage { - title: "The requested crate does not exist", - message: Some("no such crate".into()), - status: Status::NotFound, - } - .into_response(req) - } - - Nope::OwnerNotFound => ErrorPage { - title: "The requested owner does not exist", - message: Some("no such owner".into()), - status: Status::NotFound, - } - .into_response(req), - - Nope::VersionNotFound => { - // user tried to navigate to a crate with a version that does not exist - // TODO: Display the attempted crate and version - ErrorPage { - title: "The requested version does not exist", - message: Some("no such version for this crate".into()), - status: Status::NotFound, - } - .into_response(req) - } - - Nope::InternalServerError => { - // something went wrong, details should have been logged - ErrorPage { - title: "Internal server error", - message: Some("internal server error".into()), - status: Status::InternalServerError, - } - .into_response(req) - } - } - } -} - -impl From for IronError { - fn from(err: PoolError) -> IronError { - IronError::new(err, Status::InternalServerError) - } -} #[derive(Debug, thiserror::Error)] #[allow(dead_code)] // FIXME: remove after iron is gone @@ -131,6 +25,8 @@ pub enum AxumNope { InternalServerError, #[error("internal error")] InternalError(anyhow::Error), + #[error("bad request")] + BadRequest, } impl IntoResponse for AxumNope { @@ -139,7 +35,7 @@ impl IntoResponse for AxumNope { AxumNope::ResourceNotFound => { // user tried to navigate to a resource (doc page/file) that doesn't exist AxumErrorPage { - title: "Requested resource does not exist", + title: "The requested resource does not exist", message: "no such resource".into(), status: StatusCode::NOT_FOUND, } @@ -190,6 +86,12 @@ impl IntoResponse for AxumNope { } .into_response() } + AxumNope::BadRequest => AxumErrorPage { + title: "Bad request", + message: "Bad request".into(), + status: StatusCode::BAD_REQUEST, + } + .into_response(), AxumNope::InternalServerError => { // something went wrong, details should have been logged AxumErrorPage { @@ -218,23 +120,7 @@ impl From for AxumNope { fn from(err: anyhow::Error) -> Self { match err.downcast::() { Ok(axum_nope) => axum_nope, - Err(err) => match err.downcast::() { - Ok(iron_nope) => AxumNope::from(iron_nope), - Err(err) => AxumNope::InternalError(err), - }, - } - } -} - -impl From for AxumNope { - fn from(err: Nope) -> Self { - match err { - Nope::ResourceNotFound => AxumNope::ResourceNotFound, - Nope::BuildNotFound => AxumNope::BuildNotFound, - Nope::CrateNotFound => AxumNope::CrateNotFound, - Nope::OwnerNotFound => AxumNope::OwnerNotFound, - Nope::VersionNotFound => AxumNope::VersionNotFound, - Nope::InternalServerError => AxumNope::InternalServerError, + Err(err) => AxumNope::InternalError(err), } } } diff --git a/src/web/extensions.rs b/src/web/extensions.rs deleted file mode 100644 index 709b694ed..000000000 --- a/src/web/extensions.rs +++ /dev/null @@ -1,68 +0,0 @@ -use crate::web::page::TemplateData; -use crate::{ - db::Pool, repositories::RepositoryStatsUpdater, BuildQueue, Config, Context, Metrics, Storage, -}; -use anyhow::Error; -use iron::{BeforeMiddleware, IronResult, Request}; -use std::sync::Arc; - -#[derive(Debug, Clone)] -pub(super) struct InjectExtensions { - build_queue: Arc, - pool: Pool, - config: Arc, - storage: Arc, - metrics: Arc, - template_data: Arc, - repository_stats_updater: Arc, -} - -impl InjectExtensions { - pub(super) fn new( - context: &dyn Context, - template_data: Arc, - ) -> Result { - Ok(Self { - build_queue: context.build_queue()?, - pool: context.pool()?, - config: context.config()?, - storage: context.storage()?, - metrics: context.metrics()?, - repository_stats_updater: context.repository_stats_updater()?, - template_data, - }) - } -} - -impl BeforeMiddleware for InjectExtensions { - fn before(&self, req: &mut Request) -> IronResult<()> { - req.extensions - .insert::(self.build_queue.clone()); - req.extensions.insert::(self.pool.clone()); - req.extensions.insert::(self.config.clone()); - req.extensions.insert::(self.storage.clone()); - req.extensions.insert::(self.metrics.clone()); - req.extensions - .insert::(self.template_data.clone()); - req.extensions - .insert::(self.repository_stats_updater.clone()); - - Ok(()) - } -} - -macro_rules! key { - ($key:ty => $value:ty) => { - impl iron::typemap::Key for $key { - type Value = $value; - } - }; -} - -key!(BuildQueue => Arc); -key!(Pool => Pool); -key!(Config => Arc); -key!(Storage => Arc); -key!(Metrics => Arc); -key!(TemplateData => Arc); -key!(RepositoryStatsUpdater => Arc); diff --git a/src/web/file.rs b/src/web/file.rs index 659072e8b..7f25f745c 100644 --- a/src/web/file.rs +++ b/src/web/file.rs @@ -16,7 +16,6 @@ use axum::{ }, response::{IntoResponse, Response as AxumResponse}, }; -use iron::{status, Response}; use mime::Mime; #[derive(Debug)] @@ -33,29 +32,6 @@ impl File { Ok(File(storage.get(path, max_size)?)) } - - /// Consumes File and creates a iron response - pub(super) fn serve(self) -> Response { - use iron::headers::{ContentType, HttpDate, LastModified}; - - let mut response = Response::with((status::Ok, self.0.content)); - response - .headers - .set(ContentType(self.0.mime.parse().unwrap())); - - // FIXME: This is so horrible - response.headers.set(LastModified(HttpDate( - time::strptime( - &self.0.date_updated.format("%a, %d %b %Y %T %Z").to_string(), - "%a, %d %b %Y %T %Z", - ) - .unwrap(), - ))); - response - .extensions - .insert::(CachePolicy::ForeverInCdnAndBrowser); - response - } } impl IntoResponse for File { @@ -87,38 +63,6 @@ mod tests { use crate::{test::wrapper, web::cache::CachePolicy}; use chrono::Utc; use http::header::CACHE_CONTROL; - use iron::headers::CacheControl; - - #[test] - fn file_roundtrip() { - wrapper(|env| { - let now = Utc::now(); - - env.fake_release().create()?; - - let mut file = File::from_path( - &env.storage(), - "rustdoc/fake-package/1.0.0/fake-package/index.html", - &env.config(), - ) - .unwrap(); - file.0.date_updated = now; - - let resp = file.serve(); - assert!(resp.headers.get::().is_none()); - let cache = resp - .extensions - .get::() - .expect("missing cache response extension"); - assert!(matches!(cache, CachePolicy::ForeverInCdnAndBrowser)); - assert_eq!( - resp.headers.get_raw("Last-Modified").unwrap(), - [now.format("%a, %d %b %Y %T GMT").to_string().into_bytes()].as_ref(), - ); - - Ok(()) - }); - } #[test] fn file_roundtrip_axum() { diff --git a/src/web/metrics.rs b/src/web/metrics.rs index a871a2a5e..843e11bc4 100644 --- a/src/web/metrics.rs +++ b/src/web/metrics.rs @@ -11,7 +11,6 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use iron::prelude::*; use prometheus::{Encoder, HistogramVec, TextEncoder}; use std::{ borrow::Cow, @@ -94,40 +93,6 @@ pub(crate) async fn request_recorder( result } -pub(super) struct RequestRecorder { - handler: Box, - route_name: String, -} - -impl RequestRecorder { - pub fn new(handler: impl iron::Handler, route: impl Into) -> Self { - Self { - handler: Box::new(handler), - route_name: route.into(), - } - } -} - -impl iron::Handler for RequestRecorder { - fn handle(&self, request: &mut Request) -> IronResult { - let start = Instant::now(); - let result = self.handler.handle(request); - let resp_time = duration_to_seconds(start.elapsed()); - - let metrics = extension!(request, Metrics); - metrics - .routes_visited - .with_label_values(&[&self.route_name]) - .inc(); - metrics - .response_time - .with_label_values(&[&self.route_name]) - .observe(resp_time); - - result - } -} - struct RenderingTime { start: Instant, step: &'static str, diff --git a/src/web/mod.rs b/src/web/mod.rs index b651b63cd..880c4a5a9 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -3,82 +3,17 @@ pub mod page; use crate::utils::get_correct_docsrs_style_file; -use crate::utils::{report_error, spawn_blocking}; +use crate::utils::spawn_blocking; use anyhow::{anyhow, bail, Context as _, Result}; use serde_json::Value; use tracing::{info, instrument}; -/// ctry! (cratesfyitry) is extremely similar to try! and itry! -/// except it returns an error page response instead of plain Err. -#[macro_export] -macro_rules! ctry { - ($req:expr, $result:expr $(,)?) => { - match $result { - Ok(success) => success, - Err(error) => { - let request: &::iron::Request = $req; - - // This is very ugly, but it makes it impossible to get a type inference error - // from this macro - let web_error = $crate::web::ErrorPage { - title: "Internal Server Error", - message: ::std::option::Option::Some(::std::borrow::Cow::Owned(error.to_string())), - status: ::iron::status::InternalServerError, - }; - - let error = anyhow::anyhow!(error) - .context(format!("called `ctry!()` on an `Err` value while attempting to fetch the route {:?}", request.url)); - $crate::utils::report_error(&error); - - return $crate::web::page::WebPage::into_response(web_error, request); - } - } - }; -} - -/// cexpect will check an option and if it's not Some -/// it will return an error page response -macro_rules! cexpect { - ($req:expr, $option:expr $(,)?) => { - match $option { - Some(success) => success, - None => { - let request: &::iron::Request = $req; - - // This is very ugly, but it makes it impossible to get a type inference error - // from this macro - let web_error = $crate::web::ErrorPage { - title: "Internal Server Error", - message: None, - status: ::iron::status::InternalServerError, - }; - - let error = anyhow::anyhow!("called `cexpect!()` on a `None` value while attempting to fetch the route {:?}", request.url); - $crate::utils::report_error(&error); - - return $crate::web::page::WebPage::into_response(web_error, request); - } - } - }; -} - -/// Gets an extension from Request -macro_rules! extension { - ($req:expr, $ext:ty) => {{ - // Bind $req so we can have good type errors and avoid re-evaluation - let request: &::iron::Request = $req; - - cexpect!(request, request.extensions.get::<$ext>()) - }}; -} - mod build_details; mod builds; pub(crate) mod cache; pub(crate) mod crate_details; mod csp; pub(crate) mod error; -mod extensions; mod features; mod file; mod headers; @@ -91,175 +26,26 @@ mod rustdoc; mod sitemap; mod source; mod statics; -mod strangler; -use crate::{db::Pool, impl_axum_webpage, impl_webpage, Context}; +use crate::{db::Pool, impl_axum_webpage, Context}; use anyhow::Error; use axum::{ - extract::Extension, - http::{uri::Authority, StatusCode}, - middleware, - response::IntoResponse, - Router as AxumRouter, + extract::Extension, http::StatusCode, middleware, response::IntoResponse, Router as AxumRouter, }; use chrono::{DateTime, Utc}; -use csp::CspMiddleware; -use error::Nope; -use extensions::InjectExtensions; -use iron::{ - self, - headers::{Expires, HttpDate}, - modifiers::Redirect, - status, - status::Status, - Chain, Handler, Iron, IronError, IronResult, Listening, Request, Response, Url, -}; +use error::AxumNope; use page::TemplateData; use postgres::Client; -use router::{NoRoute, TrailingSlash}; use semver::{Version, VersionReq}; use serde::Serialize; use std::borrow::Borrow; use std::{borrow::Cow, net::SocketAddr, sync::Arc}; -use strangler::StranglerService; use tower::ServiceBuilder; use tower_http::trace::TraceLayer; use url::form_urlencoded; -/// Duration of static files for staticfile and DatabaseFileHandler (in seconds) -const STATIC_FILE_CACHE_DURATION: u64 = 60 * 60 * 24 * 30 * 12; // 12 months - const DEFAULT_BIND: &str = "0.0.0.0:3000"; -pub(crate) struct MainHandler { - shared_resource_handler: Box, - router_handler: Box, - inject_extensions: InjectExtensions, -} - -impl MainHandler { - fn chain(inject_extensions: InjectExtensions, base: H) -> Chain { - let mut chain = Chain::new(base); - chain.link_before(inject_extensions); - - chain.link_before(CspMiddleware); - chain.link_after(CspMiddleware); - chain.link_after(cache::CacheMiddleware); - - chain - } - - pub(crate) fn new( - template_data: Arc, - context: &dyn Context, - ) -> Result { - let inject_extensions = InjectExtensions::new(context, template_data)?; - - let routes = routes::build_routes(); - let shared_resources = Self::chain( - inject_extensions.clone(), - rustdoc::LegacySharedResourceHandler, - ); - let router_chain = Self::chain(inject_extensions.clone(), routes.iron_router()); - - Ok(MainHandler { - shared_resource_handler: Box::new(shared_resources), - router_handler: Box::new(router_chain), - inject_extensions, - }) - } -} - -impl Handler for MainHandler { - fn handle(&self, req: &mut Request) -> IronResult { - fn if_404( - e: IronError, - handle: impl FnOnce() -> IronResult, - ) -> IronResult { - if e.response.status == Some(status::NotFound) { - // the routes are ordered from least specific to most; give precedence to the - // new error message. - handle() - } else { - Err(e) - } - } - - // This is kind of a mess. - // - // Some versions of rustdoc in 2018 did not respect the shared static root - // (--static-root-path) and so emitted HTML that linked to shared static files via a local - // path. For instance, `