diff --git a/Cargo.lock b/Cargo.lock index 528da34..e3d6d1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,13 +3,282 @@ version = 3 [[package]] -name = "actix-example" +name = "actix-codec" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d5dbeb2d9e51344cb83ca7cc170f1217f9fe25bfc50160e6e200b5c31c1019a" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", + "tokio-util", +] + +[[package]] +name = "actix-http" +version = "3.0.0-beta.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd16d6b846983ffabfd081e1a67abd7698094fcbe7b3d9bcf1acbc6f546a516" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-tls", + "actix-utils", + "ahash", + "base64", + "bitflags", + "brotli2", + "bytes", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "futures-core", + "futures-util", + "h2", + "http", + "httparse", + "itoa", + "language-tags", + "local-channel", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project", + "pin-project-lite", + "rand", + "regex", + "serde", + "sha-1", + "smallvec", + "time", + "tokio", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f86cd6857c135e6e9fe57b1619a88d1f94a7df34c00e11fe13e64fd3438837" +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 = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0" +dependencies = [ + "actix-macros", + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.0.0-beta.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26369215fcc3b0176018b3b68756a8bcc275bb000e6212e454944913a1f9bf87" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "log", + "mio", + "num_cpus", + "slab", + "tokio", +] + +[[package]] +name = "actix-service" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f5f9d66a8730d0fae62c26f3424f5751e5518086628a40b7ab6fca4a705034" +dependencies = [ + "futures-core", + "paste", + "pin-project-lite", +] + +[[package]] +name = "actix-tls" +version = "3.0.0-beta.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b7bb60840962ef0332f7ea01a57d73a24d2cb663708511ff800250bbfef569" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "derive_more", + "futures-core", + "http", + "log", + "tokio-util", +] + +[[package]] +name = "actix-utils" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e491cbaac2e7fc788dfff99ff48ef317e23b3cf63dbaf7aaab6418f40f92aa94" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" version = "0.1.0" dependencies = [ + "actix-rt", + "actix-web 4.0.0-beta.8", "cache-buster", + "lazy_static", + "log", "mime", + "mime_guess", + "pretty_env_logger", + "rust-embed", ] +[[package]] +name = "actix-web" +version = "4.0.0-beta.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c503f726f895e55dac39adeafd14b5ee00cc956796314e9227fc7ae2e176f443" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "ahash", + "bytes", + "cfg-if", + "cookie", + "derive_more", + "either", + "encoding_rs", + "futures-core", + "futures-util", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "paste", + "pin-project", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2", + "time", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "0.5.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d048c6986743105c1e8e9729fbc8d5d1667f2f62393a58be8d85a7d9a5a6c8d" +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 = "ahash" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base-x" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + [[package]] name = "block-buffer" version = "0.9.0" @@ -19,6 +288,47 @@ dependencies = [ "generic-array", ] +[[package]] +name = "brotli-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "brotli2" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" +dependencies = [ + "brotli-sys", + "libc", +] + +[[package]] +name = "bumpalo" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" + +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + +[[package]] +name = "bytestring" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d" +dependencies = [ + "bytes", +] + [[package]] name = "cache-buster" version = "0.2.0" @@ -33,6 +343,15 @@ dependencies = [ "walkdir", ] +[[package]] +name = "cc" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +dependencies = [ + "jobserver", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -40,16 +359,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "cpuid-bool" -version = "0.1.2" +name = "const_fn" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" + +[[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.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf8865bac3d9a3bde5bde9088ca431b11f5d37c7a578b8086af77248b76627" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cpufeatures" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +dependencies = [ + "cfg-if", +] [[package]] name = "darling" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06d4a9551359071d1890820e3571252b91229e0712e7c36b08940e603c5a8fc" +checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c" dependencies = [ "darling_core", "darling_macro", @@ -57,9 +411,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b443e5fb0ddd56e0c9bfa47dc060c5306ee500cb731f2b91432dd65589a77684" +checksum = "8e91455b86830a1c21799d94524df0845183fa55bafd9aa137b01c7d1065fa36" dependencies = [ "fnv", "ident_case", @@ -71,9 +425,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0220073ce504f12a70efc4e7cdaea9e9b1b324872e7ad96a208056d7a638b81" +checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a" dependencies = [ "darling_core", "quote", @@ -117,6 +471,18 @@ dependencies = [ "syn", ] +[[package]] +name = "derive_more" +version = "0.99.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.9.0" @@ -126,12 +492,100 @@ dependencies = [ "generic-array", ] +[[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.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "flate2" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" +dependencies = [ + "cfg-if", + "crc32fast", + "libc", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" + +[[package]] +name = "futures-sink" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" + +[[package]] +name = "futures-task" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" + +[[package]] +name = "futures-util" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +dependencies = [ + "autocfg", + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "generic-array" version = "0.14.4" @@ -142,18 +596,194 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "h2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if", +] + [[package]] name = "itoa" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "jobserver" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd" +dependencies = [ + "libc", +] + +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" + +[[package]] +name = "local-channel" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6246c68cf195087205a0512559c97e15eaf95198bf0e206d662092cdcb03fe9f" +dependencies = [ + "futures-core", + "futures-sink", + "futures-util", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f9a2d3e27ce99ce2c3aad0b09b1a7b916293ea9b2bf624c13fe646fadd8da4" + +[[package]] +name = "lock_api" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + [[package]] name = "mime" version = "0.3.16" @@ -170,6 +800,63 @@ dependencies = [ "unicase", ] +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "mio" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -177,14 +864,111 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "proc-macro2" -version = "1.0.26" +name = "parking_lot" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + +[[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.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] +[[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.9" @@ -194,6 +978,114 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "rust-embed" +version = "5.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe1fe6aac5d6bb9e1ffd81002340363272a7648234ec7bdfac5ee202cb65523" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "5.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed91c41c42ef7bf687384439c312e75e0da9c149b0390889b94de3c7d9d9e66" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a512219132473ab0a77b52077059f1c47ce4af7fbdc94503e9862a34422876d" +dependencies = [ + "walkdir", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.5" @@ -210,19 +1102,40 @@ dependencies = [ ] [[package]] -name = "serde" -version = "1.0.125" +name = "scopeguard" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +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-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -241,18 +1154,138 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.9.3" +name = "serde_urlencoded" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16" dependencies = [ "block-buffer", "cfg-if", - "cpuid-bool", + "cpufeatures", "digest", "opaque-debug", ] +[[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + +[[package]] +name = "sha2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" + +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + +[[package]] +name = "socket2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +dependencies = [ + "libc", + "winapi", +] + +[[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", + "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" @@ -261,15 +1294,129 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[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", + "version_check", + "winapi", +] + +[[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", +] + +[[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.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +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 = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570c2eb13b3ab38208130eccd41be92520388791207fde783bda7c1e8ace28d4" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "winapi", +] + +[[package]] +name = "tokio-util" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" +dependencies = [ + "lazy_static", +] + [[package]] name = "typenum" version = "1.13.0" @@ -286,10 +1433,40 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.1" +name = "unicode-bidi" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[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" @@ -308,6 +1485,66 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" + [[package]] name = "winapi" version = "0.3.9" @@ -338,3 +1575,32 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "zstd" +version = "0.7.0+zstd.1.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9428752481d8372e15b1bf779ea518a179ad6c771cca2d2c60e4fbff3cc2cd52" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "3.1.0+zstd.1.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa1926623ad7fe406e090555387daf73db555b948134b4d73eac5eb08fb666d" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "1.5.0+zstd.1.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e6c094340240369025fc6b731b054ee2a834328fa584310ac96aa4baebdc465" +dependencies = [ + "cc", + "libc", +] diff --git a/Cargo.toml b/Cargo.toml index 354549f..52a6413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" [workspace] members = [ ".", - "actix-example" + "examples/actix-web" ] [lib] diff --git a/README.md b/README.md index b520fd8..22305c5 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,16 @@
-

Cache Buster

-

- cache-buster - A library that aids in static file cache - busting with SHA-256 hashes -

+logo image +

+ Cache Buster +

+

+ May your cache long live and prosper! +

[![Documentation](https://img.shields.io/badge/docs-master-blue)](https://realaravinth.github.io/cache-buster/cache_buster/index.html) ![CI (Linux)]() @@ -17,7 +24,7 @@ To optimise network load time, browsers cache static files. Caching greatly improves performance but how do you inform browsers to -invalidate cache when your files have changed? +invalidate cache when your files have changed? Cache busting is a simple but effective solution for this issue. There are several ways to achieve this but the way this library does this is @@ -46,6 +53,6 @@ cache-buster = { version = "0.2", git = "https://github.com/realaravinth/cache-b ## Examples: -- See [acix-example](./actix-example) +- See [acix-example](./examples/actix-web) - See [mCaptcha/guard](https://github.com/mCaptcha/guard) for use with [Sailfish](https://crates.io/crates/sailfish) template engine. diff --git a/actix-example/src/main.rs b/actix-example/src/main.rs deleted file mode 100644 index 57f4cc3..0000000 --- a/actix-example/src/main.rs +++ /dev/null @@ -1,29 +0,0 @@ -use cache_buster::Files; -use cache_buster::CACHE_BUSTER_DATA_FILE; - -fn main() { - let files = Files::new(CACHE_BUSTER_DATA_FILE); - - assert!(get_full_path_runner("../dist/log-out.svg", &files)); - assert!(get_full_path_runner( - "../dist/a/b/c/d/s/d/svg/credit-card.svg", - &files - )); - - assert!(!get_full_path_runner("dist/log-out.svg", &files)); - assert!(!get_full_path_runner( - "dist/a/b/c/d/s/d/svg/credit-card.svg", - &files - )); -} - -fn get_full_path_runner(path: &str, files: &Files) -> bool { - use std::path::Path; - - if let Some(file) = files.get_full_path(path) { - println!("{:?}", files.get(path)); - Path::new(file).exists() - } else { - false - } -} diff --git a/actix-example/.gitignore b/examples/actix-web/.gitignore similarity index 100% rename from actix-example/.gitignore rename to examples/actix-web/.gitignore diff --git a/actix-example/Cargo.toml b/examples/actix-web/Cargo.toml similarity index 50% rename from actix-example/Cargo.toml rename to examples/actix-web/Cargo.toml index 70949d7..47c6840 100644 --- a/actix-example/Cargo.toml +++ b/examples/actix-web/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "actix-example" +name = "actix-web" version = "0.1.0" authors = ["realaravinth "] edition = "2018" @@ -8,8 +8,18 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cache-buster = { path = "../"} +cache-buster = { path = "../../"} +actix-web = "4.0.0-beta.8" +rust-embed = "5.9.0" +lazy_static = "1.4" +mime = "0.3.16" +pretty_env_logger = "0.4" +log = "0.4" +mime_guess = "2.0.3" [build-dependencies] -cache-buster = { path = "../"} +cache-buster = { path = "../../"} mime = "0.3.16" + +[dev-dependencies] +actix-rt = "2" diff --git a/actix-example/build.rs b/examples/actix-web/build.rs similarity index 80% rename from actix-example/build.rs rename to examples/actix-web/build.rs index ba426e5..65c8d97 100644 --- a/actix-example/build.rs +++ b/examples/actix-web/build.rs @@ -6,11 +6,12 @@ fn main() { mime::IMAGE_SVG, mime::IMAGE_JPEG, mime::IMAGE_GIF, + mime::TEXT_CSS, ]; let config = BusterBuilder::default() - .source("../dist") - .result("./prod") + .source("./static/cachable/") + .result("./dist") .mime_types(types) .copy(true) .follow_links(true) diff --git a/examples/actix-web/dist/css/main.C9D814A73388500CC43B26842F4EE585CD53535A6EC915A3153DC5107C1FA1C1.css b/examples/actix-web/dist/css/main.C9D814A73388500CC43B26842F4EE585CD53535A6EC915A3153DC5107C1FA1C1.css new file mode 100644 index 0000000..68cdb49 --- /dev/null +++ b/examples/actix-web/dist/css/main.C9D814A73388500CC43B26842F4EE585CD53535A6EC915A3153DC5107C1FA1C1.css @@ -0,0 +1,27 @@ +body { + display: flex; + flex-direction: column; + background-color: #22272e; + color: #adbac7; + max-width: 60%; + margin: auto; + padding: 20px; +} +.greetings { + display: block; + margin: auto; +} + +h1, +h2 { + margin: auto; + padding: 10px; +} + +code { + font-size: 0.9rem; + color: #adbac7; + background-color: rgba(205, 217, 229, 0.15); + border-radius: 6px; + padding: 0.2em 0.4em; +} diff --git a/examples/actix-web/dist/img/Spock_vulcan-salute.50BD6BD857160173DDF9A35A751F5755A3ED3B471F1628D5CD0542B635C18068.png b/examples/actix-web/dist/img/Spock_vulcan-salute.50BD6BD857160173DDF9A35A751F5755A3ED3B471F1628D5CD0542B635C18068.png new file mode 100644 index 0000000..f9c03e4 Binary files /dev/null and b/examples/actix-web/dist/img/Spock_vulcan-salute.50BD6BD857160173DDF9A35A751F5755A3ED3B471F1628D5CD0542B635C18068.png differ diff --git a/examples/actix-web/dist/svg/bell.9DA292704EE9907EFDB870F4510C97336977CA27FBFAAD83CF46F8E22D3828F7.svg b/examples/actix-web/dist/svg/bell.9DA292704EE9907EFDB870F4510C97336977CA27FBFAAD83CF46F8E22D3828F7.svg new file mode 100644 index 0000000..c0ed0e1 --- /dev/null +++ b/examples/actix-web/dist/svg/bell.9DA292704EE9907EFDB870F4510C97336977CA27FBFAAD83CF46F8E22D3828F7.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/credit-card.DF612AFE367A7B31410F2F6CD3C7B515B0F1889C0107EA695D840DFFA492E07D.svg b/examples/actix-web/dist/svg/credit-card.DF612AFE367A7B31410F2F6CD3C7B515B0F1889C0107EA695D840DFFA492E07D.svg new file mode 100644 index 0000000..9429a63 --- /dev/null +++ b/examples/actix-web/dist/svg/credit-card.DF612AFE367A7B31410F2F6CD3C7B515B0F1889C0107EA695D840DFFA492E07D.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/eye-off.939360B335D1D35B57C3E2070129D14ABB168E4AC137B5BE4F6F8BD450B712F5.svg b/examples/actix-web/dist/svg/eye-off.939360B335D1D35B57C3E2070129D14ABB168E4AC137B5BE4F6F8BD450B712F5.svg new file mode 100644 index 0000000..9d28c18 --- /dev/null +++ b/examples/actix-web/dist/svg/eye-off.939360B335D1D35B57C3E2070129D14ABB168E4AC137B5BE4F6F8BD450B712F5.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/eye.9DE4D24D3C9B055D02B94A8AD65E8C0C644852381FDD131A64448B6DA7859167.svg b/examples/actix-web/dist/svg/eye.9DE4D24D3C9B055D02B94A8AD65E8C0C644852381FDD131A64448B6DA7859167.svg new file mode 100644 index 0000000..44f107a --- /dev/null +++ b/examples/actix-web/dist/svg/eye.9DE4D24D3C9B055D02B94A8AD65E8C0C644852381FDD131A64448B6DA7859167.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/file-text.CF57DF252051E7E81C240D36AF1DB8A9DDAF282F9A5E8C338408FE88A6545A02.svg b/examples/actix-web/dist/svg/file-text.CF57DF252051E7E81C240D36AF1DB8A9DDAF282F9A5E8C338408FE88A6545A02.svg new file mode 100644 index 0000000..85186e3 --- /dev/null +++ b/examples/actix-web/dist/svg/file-text.CF57DF252051E7E81C240D36AF1DB8A9DDAF282F9A5E8C338408FE88A6545A02.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/file.F9E376D9F78FFD918D8D592A8B2D97EAAC14E638B5A7AE3C58DDB075375D8E0E.svg b/examples/actix-web/dist/svg/file.F9E376D9F78FFD918D8D592A8B2D97EAAC14E638B5A7AE3C58DDB075375D8E0E.svg new file mode 100644 index 0000000..fa1ecc8 --- /dev/null +++ b/examples/actix-web/dist/svg/file.F9E376D9F78FFD918D8D592A8B2D97EAAC14E638B5A7AE3C58DDB075375D8E0E.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/filter.6D5FBD96BA2E2020663AAC4994A991295917D73F3592C07EE103647B655A2275.svg b/examples/actix-web/dist/svg/filter.6D5FBD96BA2E2020663AAC4994A991295917D73F3592C07EE103647B655A2275.svg new file mode 100644 index 0000000..3ae2cfc --- /dev/null +++ b/examples/actix-web/dist/svg/filter.6D5FBD96BA2E2020663AAC4994A991295917D73F3592C07EE103647B655A2275.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/github.FA9EB1C66F548EC2C7598B94BA6A17275E1EA383D42B6C83351A2388C773E621.svg b/examples/actix-web/dist/svg/github.FA9EB1C66F548EC2C7598B94BA6A17275E1EA383D42B6C83351A2388C773E621.svg new file mode 100644 index 0000000..8a1c9c0 --- /dev/null +++ b/examples/actix-web/dist/svg/github.FA9EB1C66F548EC2C7598B94BA6A17275E1EA383D42B6C83351A2388C773E621.svg @@ -0,0 +1 @@ + diff --git a/examples/actix-web/dist/svg/globe.44C2A069EBD637663E938ECE7B8E4EC2A8BDE049A8A044EC68D9CB69AE8C592E.svg b/examples/actix-web/dist/svg/globe.44C2A069EBD637663E938ECE7B8E4EC2A8BDE049A8A044EC68D9CB69AE8C592E.svg new file mode 100644 index 0000000..4306cdc --- /dev/null +++ b/examples/actix-web/dist/svg/globe.44C2A069EBD637663E938ECE7B8E4EC2A8BDE049A8A044EC68D9CB69AE8C592E.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/help-circle.BE230ABD2E05EB05EF6C5B7D04D35A3A43637EF1E046DEF3D244425609B99F81.svg b/examples/actix-web/dist/svg/help-circle.BE230ABD2E05EB05EF6C5B7D04D35A3A43637EF1E046DEF3D244425609B99F81.svg new file mode 100644 index 0000000..1bbf397 --- /dev/null +++ b/examples/actix-web/dist/svg/help-circle.BE230ABD2E05EB05EF6C5B7D04D35A3A43637EF1E046DEF3D244425609B99F81.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/home.28C26C2D3E4013D24D755A589A80D8DD5C49DA5397032E3F09B76BC3A2C314ED.svg b/examples/actix-web/dist/svg/home.28C26C2D3E4013D24D755A589A80D8DD5C49DA5397032E3F09B76BC3A2C314ED.svg new file mode 100644 index 0000000..867f079 --- /dev/null +++ b/examples/actix-web/dist/svg/home.28C26C2D3E4013D24D755A589A80D8DD5C49DA5397032E3F09B76BC3A2C314ED.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/log-out.92AB4384FD41D9AFE4735C480361BB64789CD767B7DD0FF3C6F56287B3D4498E.svg b/examples/actix-web/dist/svg/log-out.92AB4384FD41D9AFE4735C480361BB64789CD767B7DD0FF3C6F56287B3D4498E.svg new file mode 100644 index 0000000..625d272 --- /dev/null +++ b/examples/actix-web/dist/svg/log-out.92AB4384FD41D9AFE4735C480361BB64789CD767B7DD0FF3C6F56287B3D4498E.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/menu.A2C4DD00686F5D23F78885AC4CE3E075FCA78DFBDEA70407667FBBD9801B7A75.svg b/examples/actix-web/dist/svg/menu.A2C4DD00686F5D23F78885AC4CE3E075FCA78DFBDEA70407667FBBD9801B7A75.svg new file mode 100644 index 0000000..0ea1741 --- /dev/null +++ b/examples/actix-web/dist/svg/menu.A2C4DD00686F5D23F78885AC4CE3E075FCA78DFBDEA70407667FBBD9801B7A75.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/moon.1E151D68949CA3B2DC7DE34BC25B7586E4175AC3BA7F56DDBB34227334EF7155.svg b/examples/actix-web/dist/svg/moon.1E151D68949CA3B2DC7DE34BC25B7586E4175AC3BA7F56DDBB34227334EF7155.svg new file mode 100644 index 0000000..3d94f16 --- /dev/null +++ b/examples/actix-web/dist/svg/moon.1E151D68949CA3B2DC7DE34BC25B7586E4175AC3BA7F56DDBB34227334EF7155.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/settings.910C6241743C9C694141971BE8E1C4016A1A5BF203E4E9D676D4CE93BD518F4C.svg b/examples/actix-web/dist/svg/settings.910C6241743C9C694141971BE8E1C4016A1A5BF203E4E9D676D4CE93BD518F4C.svg new file mode 100644 index 0000000..0318f2c --- /dev/null +++ b/examples/actix-web/dist/svg/settings.910C6241743C9C694141971BE8E1C4016A1A5BF203E4E9D676D4CE93BD518F4C.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/shield-off.85394A6AD92D550F8EBA72AAB095E078E7A0E3359DF81174532C8D1AF53B5876.svg b/examples/actix-web/dist/svg/shield-off.85394A6AD92D550F8EBA72AAB095E078E7A0E3359DF81174532C8D1AF53B5876.svg new file mode 100644 index 0000000..47805ee --- /dev/null +++ b/examples/actix-web/dist/svg/shield-off.85394A6AD92D550F8EBA72AAB095E078E7A0E3359DF81174532C8D1AF53B5876.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/shield.13AFE15DCB4882B4A940CFDC3E2088A733CD4E6F97F25B211D87C7C9D6DBA2B6.svg b/examples/actix-web/dist/svg/shield.13AFE15DCB4882B4A940CFDC3E2088A733CD4E6F97F25B211D87C7C9D6DBA2B6.svg new file mode 100644 index 0000000..18c6ed2 --- /dev/null +++ b/examples/actix-web/dist/svg/shield.13AFE15DCB4882B4A940CFDC3E2088A733CD4E6F97F25B211D87C7C9D6DBA2B6.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/tag.E0BC111B8E81BBFC62B6A9E7E4AC162B7085A6543D995B7A0030CB7632901BD4.svg b/examples/actix-web/dist/svg/tag.E0BC111B8E81BBFC62B6A9E7E4AC162B7085A6543D995B7A0030CB7632901BD4.svg new file mode 100644 index 0000000..0c7a770 --- /dev/null +++ b/examples/actix-web/dist/svg/tag.E0BC111B8E81BBFC62B6A9E7E4AC162B7085A6543D995B7A0030CB7632901BD4.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/toggle-left.E421950C5922E84015F0A86F272AE5637A2ED96E267D2C962543F5994E5D1172.svg b/examples/actix-web/dist/svg/toggle-left.E421950C5922E84015F0A86F272AE5637A2ED96E267D2C962543F5994E5D1172.svg new file mode 100644 index 0000000..cd4b4e6 --- /dev/null +++ b/examples/actix-web/dist/svg/toggle-left.E421950C5922E84015F0A86F272AE5637A2ED96E267D2C962543F5994E5D1172.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/toggle-right.15BF49887941593CE3FE09FA73E3CAF1F4B1E8ABCB42A23D85B4FCBC24FDF5AA.svg b/examples/actix-web/dist/svg/toggle-right.15BF49887941593CE3FE09FA73E3CAF1F4B1E8ABCB42A23D85B4FCBC24FDF5AA.svg new file mode 100644 index 0000000..01392ab --- /dev/null +++ b/examples/actix-web/dist/svg/toggle-right.15BF49887941593CE3FE09FA73E3CAF1F4B1E8ABCB42A23D85B4FCBC24FDF5AA.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/dist/svg/user.B164ECD2C4A09DC5189F1F252487E2AC6A33646BEA67AF9C528CDA61FE5E146F.svg b/examples/actix-web/dist/svg/user.B164ECD2C4A09DC5189F1F252487E2AC6A33646BEA67AF9C528CDA61FE5E146F.svg new file mode 100644 index 0000000..7b5bc4a --- /dev/null +++ b/examples/actix-web/dist/svg/user.B164ECD2C4A09DC5189F1F252487E2AC6A33646BEA67AF9C528CDA61FE5E146F.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/src/cache_buster_data.json b/examples/actix-web/src/cache_buster_data.json new file mode 100644 index 0000000..0ddf197 --- /dev/null +++ b/examples/actix-web/src/cache_buster_data.json @@ -0,0 +1 @@ +{"map":{"./static/cachable/svg/file-text.svg":"./dist/svg/file-text.CF57DF252051E7E81C240D36AF1DB8A9DDAF282F9A5E8C338408FE88A6545A02.svg","./static/cachable/svg/credit-card.svg":"./dist/svg/credit-card.DF612AFE367A7B31410F2F6CD3C7B515B0F1889C0107EA695D840DFFA492E07D.svg","./static/cachable/svg/github.svg":"./dist/svg/github.FA9EB1C66F548EC2C7598B94BA6A17275E1EA383D42B6C83351A2388C773E621.svg","./static/cachable/svg/user.svg":"./dist/svg/user.B164ECD2C4A09DC5189F1F252487E2AC6A33646BEA67AF9C528CDA61FE5E146F.svg","./static/cachable/svg/toggle-right.svg":"./dist/svg/toggle-right.15BF49887941593CE3FE09FA73E3CAF1F4B1E8ABCB42A23D85B4FCBC24FDF5AA.svg","./static/cachable/svg/toggle-left.svg":"./dist/svg/toggle-left.E421950C5922E84015F0A86F272AE5637A2ED96E267D2C962543F5994E5D1172.svg","./static/cachable/svg/bell.svg":"./dist/svg/bell.9DA292704EE9907EFDB870F4510C97336977CA27FBFAAD83CF46F8E22D3828F7.svg","./static/cachable/svg/file.svg":"./dist/svg/file.F9E376D9F78FFD918D8D592A8B2D97EAAC14E638B5A7AE3C58DDB075375D8E0E.svg","./static/cachable/svg/shield-off.svg":"./dist/svg/shield-off.85394A6AD92D550F8EBA72AAB095E078E7A0E3359DF81174532C8D1AF53B5876.svg","./static/cachable/svg/eye-off.svg":"./dist/svg/eye-off.939360B335D1D35B57C3E2070129D14ABB168E4AC137B5BE4F6F8BD450B712F5.svg","./static/cachable/svg/log-out.svg":"./dist/svg/log-out.92AB4384FD41D9AFE4735C480361BB64789CD767B7DD0FF3C6F56287B3D4498E.svg","./static/cachable/svg/eye.svg":"./dist/svg/eye.9DE4D24D3C9B055D02B94A8AD65E8C0C644852381FDD131A64448B6DA7859167.svg","./static/cachable/svg/globe.svg":"./dist/svg/globe.44C2A069EBD637663E938ECE7B8E4EC2A8BDE049A8A044EC68D9CB69AE8C592E.svg","./static/cachable/svg/filter.svg":"./dist/svg/filter.6D5FBD96BA2E2020663AAC4994A991295917D73F3592C07EE103647B655A2275.svg","./static/cachable/svg/settings.svg":"./dist/svg/settings.910C6241743C9C694141971BE8E1C4016A1A5BF203E4E9D676D4CE93BD518F4C.svg","./static/cachable/svg/tag.svg":"./dist/svg/tag.E0BC111B8E81BBFC62B6A9E7E4AC162B7085A6543D995B7A0030CB7632901BD4.svg","./static/cachable/svg/moon.svg":"./dist/svg/moon.1E151D68949CA3B2DC7DE34BC25B7586E4175AC3BA7F56DDBB34227334EF7155.svg","./static/cachable/svg/menu.svg":"./dist/svg/menu.A2C4DD00686F5D23F78885AC4CE3E075FCA78DFBDEA70407667FBBD9801B7A75.svg","./static/cachable/img/Spock_vulcan-salute.png":"./dist/img/Spock_vulcan-salute.50BD6BD857160173DDF9A35A751F5755A3ED3B471F1628D5CD0542B635C18068.png","./static/cachable/svg/home.svg":"./dist/svg/home.28C26C2D3E4013D24D755A589A80D8DD5C49DA5397032E3F09B76BC3A2C314ED.svg","./static/cachable/svg/help-circle.svg":"./dist/svg/help-circle.BE230ABD2E05EB05EF6C5B7D04D35A3A43637EF1E046DEF3D244425609B99F81.svg","./static/cachable/svg/shield.svg":"./dist/svg/shield.13AFE15DCB4882B4A940CFDC3E2088A733CD4E6F97F25B211D87C7C9D6DBA2B6.svg","./static/cachable/css/main.css":"./dist/css/main.C9D814A73388500CC43B26842F4EE585CD53535A6EC915A3153DC5107C1FA1C1.css"},"base_dir":"./dist"} \ No newline at end of file diff --git a/examples/actix-web/src/index.rs b/examples/actix-web/src/index.rs new file mode 100644 index 0000000..b83d23a --- /dev/null +++ b/examples/actix-web/src/index.rs @@ -0,0 +1,67 @@ +pub fn get_index() -> String { + let template = format!( + " + + + + + + Cache buster Actix Web example + + + logo image +

+ Cache Buster +

+

+ May your cache long live and prosper! +

+ +

What is cache busting?

+ +

+ To optimise network load time, browsers cache static files. Caching + greatly improves performance but how do you inform browsers to invalidate + cache when your files have changed? +

+

+ Cache busting is a simple but effective solution for this issue. There are + several ways to achieve this but the way this library does this is by + changing file names to include the hash of the files' contents. So if you + have bundle.js, it will become + bundle.long-sha256-hash.js. This lets you set a super long + cache age as, because of the file names changing, the path to the + filename, too, will change. So as far as the browser is concerned, you are + trying to load a file that it doesn't have. +

+

+ Pretty neat, isn't it? +

+ +

Features

+
    +
  • SHA-256 based name generation during compile-time
  • +
  • Processes files based on provided MIME filters
  • +
  • + Exposes modified names to program during runtime +
  • +
  • + Route prefixes(optional) +
  • +
+ + +", + crate::FILES + .get_full_path("./static/cachable/img/Spock_vulcan-salute.png") + .unwrap(), + crate::FILES + .get_full_path("./static/cachable/css/main.css") + .unwrap() + ); + template +} diff --git a/examples/actix-web/src/main.rs b/examples/actix-web/src/main.rs new file mode 100644 index 0000000..94e7fc8 --- /dev/null +++ b/examples/actix-web/src/main.rs @@ -0,0 +1,169 @@ +use std::borrow::Cow; + +use actix_web::body::Body; +use actix_web::{get, http::header, web, HttpResponse, Responder}; +use actix_web::{App, HttpServer}; +use lazy_static::lazy_static; +use log::info; +use mime_guess::from_path; +use rust_embed::RustEmbed; + +use cache_buster::Files; + +mod index; +pub const CACHE_AGE: u32 = 60 * 60 * 24 * 365; + +lazy_static! { + pub static ref FILES: Files = { + let map = include_str!("./cache_buster_data.json"); + Files::new(&map) + }; + pub static ref INDEX: String = index::get_index(); +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + std::env::set_var("RUST_LOG", "info"); + + let ip = "localhost:2080"; + crate::FILES + .get_full_path("./static/cachable/img/Spock_vulcan-salute.png") + .expect("unable to find Spock Vulcan salute image"); + crate::FILES + .get("./static/cachable/css/main.css") + .expect("unable to find CSS"); + + pretty_env_logger::init(); + + info!("Starting server at http://{}", &ip); + HttpServer::new(move || { + App::new() + .wrap(actix_web::middleware::Logger::default()) + .configure(services) + }) + .bind(ip) + .unwrap() + .run() + .await?; + Ok(()) +} + +#[derive(RustEmbed)] +#[folder = "dist/"] +struct Asset; + +fn handle_assets(path: &str) -> HttpResponse { + match Asset::get(path) { + Some(content) => { + let body: Body = match content { + Cow::Borrowed(bytes) => bytes.into(), + Cow::Owned(bytes) => bytes.into(), + }; + + HttpResponse::Ok() + .insert_header(header::CacheControl(vec![ + header::CacheDirective::Public, + header::CacheDirective::Extension("immutable".into(), None), + header::CacheDirective::MaxAge(CACHE_AGE), + ])) + .content_type(from_path(path).first_or_octet_stream().as_ref()) + .body(body) + } + None => HttpResponse::NotFound().body("404 Not Found"), + } +} + +#[get("/dist/{_:.*}")] +pub async fn static_files(path: web::Path) -> impl Responder { + info!("fetching file: {}", &path); + handle_assets(&path) +} + +#[get("/")] +pub async fn serve_index() -> impl Responder { + HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(&*INDEX) +} + +#[derive(RustEmbed)] +#[folder = "static/no-cache/"] +struct Favicons; + +fn handle_favicons(path: &str) -> HttpResponse { + match Favicons::get(path) { + Some(content) => { + let body: Body = match content { + Cow::Borrowed(bytes) => bytes.into(), + Cow::Owned(bytes) => bytes.into(), + }; + + HttpResponse::Ok() + .insert_header(header::CacheControl(vec![ + header::CacheDirective::Public, + header::CacheDirective::Extension("immutable".into(), None), + header::CacheDirective::MaxAge(CACHE_AGE), + ])) + .content_type(from_path(path).first_or_octet_stream().as_ref()) + .body(body) + } + None => HttpResponse::NotFound().body("404 Not Found"), + } +} + +#[get("/{file}")] +pub async fn favicons(path: web::Path) -> impl Responder { + handle_favicons(&path) +} + +fn services(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(static_files); + cfg.service(serve_index); + cfg.service(favicons); +} + +#[cfg(test)] +mod tests { + use actix_web::http::StatusCode; + use actix_web::test; + + use super::*; + + #[actix_rt::test] + async fn static_assets_work() { + let mut app = test::init_service(App::new().configure(services)).await; + + let img_resp = test::call_service( + &mut app, + test::TestRequest::get() + .uri( + &crate::FILES + .get_full_path("./static/cachable/img/Spock_vulcan-salute.png") + .unwrap()[1..], + ) + .to_request(), + ) + .await; + assert_eq!(img_resp.status(), StatusCode::OK); + + let css_resp = test::call_service( + &mut app, + test::TestRequest::get() + .uri( + &crate::FILES + .get_full_path("./static/cachable/img/Spock_vulcan-salute.png") + .unwrap()[1..], + ) + .to_request(), + ) + .await; + assert_eq!(css_resp.status(), StatusCode::OK); + + let favicon_resp = test::call_service( + &mut app, + test::TestRequest::get().uri("/favicon.ico").to_request(), + ) + .await; + assert_eq!(favicon_resp.status(), StatusCode::OK); + } +} diff --git a/examples/actix-web/static/cachable/css/main.css b/examples/actix-web/static/cachable/css/main.css new file mode 100644 index 0000000..68cdb49 --- /dev/null +++ b/examples/actix-web/static/cachable/css/main.css @@ -0,0 +1,27 @@ +body { + display: flex; + flex-direction: column; + background-color: #22272e; + color: #adbac7; + max-width: 60%; + margin: auto; + padding: 20px; +} +.greetings { + display: block; + margin: auto; +} + +h1, +h2 { + margin: auto; + padding: 10px; +} + +code { + font-size: 0.9rem; + color: #adbac7; + background-color: rgba(205, 217, 229, 0.15); + border-radius: 6px; + padding: 0.2em 0.4em; +} diff --git a/examples/actix-web/static/cachable/img/Spock_vulcan-salute.png b/examples/actix-web/static/cachable/img/Spock_vulcan-salute.png new file mode 100644 index 0000000..f9c03e4 Binary files /dev/null and b/examples/actix-web/static/cachable/img/Spock_vulcan-salute.png differ diff --git a/examples/actix-web/static/cachable/index.html b/examples/actix-web/static/cachable/index.html new file mode 100644 index 0000000..a78b94a --- /dev/null +++ b/examples/actix-web/static/cachable/index.html @@ -0,0 +1,55 @@ + + + + + + Cache buster Actix Web example + + + logo image +

+ Cache Buster +

+

+ May your cache long live and prosper! +

+ +

What is cache busting?

+ +

+ To optimise network load time, browsers cache static files. Caching + greatly improves performance but how do you inform browsers to invalidate + cache when your files have changed? +

+

+ Cache busting is a simple but effective solution for this issue. There are + several ways to achieve this but the way this library does this is by + changing file names to include the hash of the files' contents. So if you + have bundle.js, it will become + bundle.long-sha256-hash.js. This lets you set a super long + cache age as, because of the file names changing, the path to the + filename, too, will change. So as far as the browser is concerned, you are + trying to load a file that it doesn't have. +

+

+ Pretty neat, isn't it? +

+ +

Features

+
    +
  • SHA-256 based name generation during compile-time
  • +
  • Processes files based on provided MIME filters
  • +
  • + Exposes modified names to program during runtime +
  • +
  • + Route prefixes(optional) +
  • +
+ + + diff --git a/examples/actix-web/static/cachable/svg/bell.svg b/examples/actix-web/static/cachable/svg/bell.svg new file mode 100644 index 0000000..c0ed0e1 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/bell.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/credit-card.svg b/examples/actix-web/static/cachable/svg/credit-card.svg new file mode 100644 index 0000000..9429a63 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/credit-card.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/eye-off.svg b/examples/actix-web/static/cachable/svg/eye-off.svg new file mode 100644 index 0000000..9d28c18 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/eye-off.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/eye.svg b/examples/actix-web/static/cachable/svg/eye.svg new file mode 100644 index 0000000..44f107a --- /dev/null +++ b/examples/actix-web/static/cachable/svg/eye.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/file-text.svg b/examples/actix-web/static/cachable/svg/file-text.svg new file mode 100644 index 0000000..85186e3 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/file-text.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/file.svg b/examples/actix-web/static/cachable/svg/file.svg new file mode 100644 index 0000000..fa1ecc8 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/filter.svg b/examples/actix-web/static/cachable/svg/filter.svg new file mode 100644 index 0000000..3ae2cfc --- /dev/null +++ b/examples/actix-web/static/cachable/svg/filter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/github.svg b/examples/actix-web/static/cachable/svg/github.svg new file mode 100644 index 0000000..8a1c9c0 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/github.svg @@ -0,0 +1 @@ + diff --git a/examples/actix-web/static/cachable/svg/globe.svg b/examples/actix-web/static/cachable/svg/globe.svg new file mode 100644 index 0000000..4306cdc --- /dev/null +++ b/examples/actix-web/static/cachable/svg/globe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/help-circle.svg b/examples/actix-web/static/cachable/svg/help-circle.svg new file mode 100644 index 0000000..1bbf397 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/help-circle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/home.svg b/examples/actix-web/static/cachable/svg/home.svg new file mode 100644 index 0000000..867f079 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/home.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/log-out.svg b/examples/actix-web/static/cachable/svg/log-out.svg new file mode 100644 index 0000000..625d272 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/log-out.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/menu.svg b/examples/actix-web/static/cachable/svg/menu.svg new file mode 100644 index 0000000..0ea1741 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/menu.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/moon.svg b/examples/actix-web/static/cachable/svg/moon.svg new file mode 100644 index 0000000..3d94f16 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/moon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/settings.svg b/examples/actix-web/static/cachable/svg/settings.svg new file mode 100644 index 0000000..0318f2c --- /dev/null +++ b/examples/actix-web/static/cachable/svg/settings.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/shield-off.svg b/examples/actix-web/static/cachable/svg/shield-off.svg new file mode 100644 index 0000000..47805ee --- /dev/null +++ b/examples/actix-web/static/cachable/svg/shield-off.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/shield.svg b/examples/actix-web/static/cachable/svg/shield.svg new file mode 100644 index 0000000..18c6ed2 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/shield.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/tag.svg b/examples/actix-web/static/cachable/svg/tag.svg new file mode 100644 index 0000000..0c7a770 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/tag.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/toggle-left.svg b/examples/actix-web/static/cachable/svg/toggle-left.svg new file mode 100644 index 0000000..cd4b4e6 --- /dev/null +++ b/examples/actix-web/static/cachable/svg/toggle-left.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/toggle-right.svg b/examples/actix-web/static/cachable/svg/toggle-right.svg new file mode 100644 index 0000000..01392ab --- /dev/null +++ b/examples/actix-web/static/cachable/svg/toggle-right.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/cachable/svg/user.svg b/examples/actix-web/static/cachable/svg/user.svg new file mode 100644 index 0000000..7b5bc4a --- /dev/null +++ b/examples/actix-web/static/cachable/svg/user.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/actix-web/static/no-cache/favicon-16x16.png b/examples/actix-web/static/no-cache/favicon-16x16.png new file mode 100644 index 0000000..8e76a1b Binary files /dev/null and b/examples/actix-web/static/no-cache/favicon-16x16.png differ diff --git a/examples/actix-web/static/no-cache/favicon-32x32.png b/examples/actix-web/static/no-cache/favicon-32x32.png new file mode 100644 index 0000000..83c85ae Binary files /dev/null and b/examples/actix-web/static/no-cache/favicon-32x32.png differ diff --git a/examples/actix-web/static/no-cache/favicon.ico b/examples/actix-web/static/no-cache/favicon.ico new file mode 100644 index 0000000..69ea1ac Binary files /dev/null and b/examples/actix-web/static/no-cache/favicon.ico differ