From 196f1edb086483b3ed08e3b417343a153669ffe9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 26 Mar 2022 13:43:52 +0000 Subject: [PATCH] actix: experiments: Test program: CORS Partially C&P from Actix docs. Signed-off-by: Ian Jackson --- Cargo.lock | 16 ++++++++++++++++ daemon/Cargo.toml | 1 + daemon/actix-test.rs | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 68325fb6..b8da1555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tokio-util 0.7.0", ] +[[package]] +name = "actix-cors" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414360eed71ba2d5435b185ba43ecbe281dfab5df3898286d6b7be8074372c92" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log 0.4.16", + "once_cell", + "smallvec", +] + [[package]] name = "actix-files" version = "0.6.0" @@ -2892,6 +2907,7 @@ dependencies = [ name = "otter-daemon" version = "0.7.3" dependencies = [ + "actix-cors", "actix-files", "actix-web", "fehler", diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index 9119531f..9a1dbb74 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -44,6 +44,7 @@ structopt="0.3" actix-web = "4" actix-files = "0.6" +actix-cors = "0.6" rocket = { version="^0.4.6", features=["sse"] } rocket_contrib = { version="0.4", default-features=false, features=["tera_templates", "helmet", "json", "serve"] } diff --git a/daemon/actix-test.rs b/daemon/actix-test.rs index a17d5c73..27c71b66 100644 --- a/daemon/actix-test.rs +++ b/daemon/actix-test.rs @@ -8,6 +8,7 @@ use actix_web::http::Method; use actix_web::HttpResponse; use actix_web::dev::Payload; use actix_web::middleware; +use actix_cors::Cors; use std::convert::Infallible; @@ -44,8 +45,15 @@ async fn wombat(remain: Remain) -> impl Responder { format!("Hello {:?}", remain) } +fn update_cors() -> Cors { + Cors::default() + .allowed_methods([Method::GET]) + +} + //#[route("/wombat", method="GET", method="HEAD")] -#[route("/foo", method="GET", method="HEAD")] +#[route("/foo", method="GET", method="HEAD", + wrap = "update_cors()")] //#[get("/foo")] async fn foo() -> impl Responder { "foo\r\n" -- 2.30.2