From b618ff1b1cd3ea30d2705b21db31be042d89309f Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Fri, 27 Jan 2023 16:12:19 +0100 Subject: [PATCH] task: added etag middleware (#22) --- Cargo.lock | 55 ++++++++++++++++++++++++++++++++++++++++++++-- server/Cargo.toml | 2 ++ server/src/main.rs | 2 ++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c52c22e..ae3d3b3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,7 +46,7 @@ dependencies = [ "actix-tls", "actix-utils", "ahash", - "base64", + "base64 0.21.0", "bitflags", "brotli", "bytes", @@ -84,6 +84,19 @@ dependencies = [ "syn", ] +[[package]] +name = "actix-middleware-etag" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44ad18cee06216ed944a2bf2d0b9565a879a89ea52d738f8dd8173c8910cd768" +dependencies = [ + "actix-service", + "actix-web", + "base64 0.13.1", + "futures", + "xxhash-rust", +] + [[package]] name = "actix-router" version = "0.5.1" @@ -327,6 +340,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.0" @@ -817,6 +836,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.25" @@ -824,6 +858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -843,6 +878,12 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + [[package]] name = "futures-macro" version = "0.3.25" @@ -872,10 +913,13 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -1685,7 +1729,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -2229,6 +2273,7 @@ name = "unleash-edge" version = "0.0.0" dependencies = [ "actix-cors", + "actix-middleware-etag", "actix-tls", "actix-web", "actix-web-opentelemetry", @@ -2510,6 +2555,12 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "xxhash-rust" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "735a71d46c4d68d71d4b24d03fdc2b98e38cea81730595801db779c04fe80d70" + [[package]] name = "zstd" version = "0.12.2+zstd.1.5.2" diff --git a/server/Cargo.toml b/server/Cargo.toml index 86d01e25..93b6ee92 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -10,9 +10,11 @@ homepage = "https://github.com/Unleash/unleash-edge" [dependencies] actix-cors = "0.6.4" +actix-middleware-etag = "0.1.1" actix-tls = { version = "3.0.3", features = ["rustls"] } actix-web = { version = "4.3.0", features = ["rustls"] } actix-web-opentelemetry = { version = "0.13.0", features = ["metrics", "metrics-prometheus"] } + anyhow = "1.0.68" chrono = { version = "0.4.23", features = ["serde"] } clap = { version = "4.1.4", features = ["derive", "env"] } diff --git a/server/src/main.rs b/server/src/main.rs index 72ff49b0..a479a511 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use crate::cli::EdgeMode; use crate::offline_provider::OfflineProvider; use actix_cors::Cors; +use actix_middleware_etag::Etag; use actix_web::{http, middleware, web, App, HttpServer}; use actix_web_opentelemetry::RequestTracing; use clap::Parser; @@ -45,6 +46,7 @@ async fn main() -> Result<(), anyhow::Error> { .allowed_header(http::header::CONTENT_TYPE); App::new() .app_data(client_provider_data) + .wrap(Etag::default()) .wrap(cors_middleware) .wrap(RequestTracing::new()) .wrap(request_metrics.clone())