diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 8c0fec43c..b29e99eb0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,35 +3,41 @@ name: bug report about: create a bug report --- -Your issue may already be reported! -Please search on the [actix-extras issue tracker](https://github.com/actix/actix-extras/issues) before creating one. +Your issue may already be reported! Please search on the [actix-extras issue tracker](https://github.com/actix/actix-extras/issues) before creating one. ## Expected Behavior + ## Current Behavior + ## Possible Solution + ## Steps to Reproduce (for bugs) + + 1. 2. 3. 4. ## Context + ## Your Environment + -* Rust Version (I.e, output of `rustc -V`): -* Actix-* crate(s) Version: +- Rust version (output of `rustc -V`): +- `actix-*` crate versions: diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1c3875860..39fece8b9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,12 +2,14 @@ ## PR Type + + INSERT_PR_TYPE - ## PR Checklist + @@ -16,11 +18,10 @@ INSERT_PR_TYPE - [ ] A changelog entry has been made for the appropriate packages. - [ ] Format code with the nightly rustfmt (`cargo +nightly fmt`). - ## Overview + - diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 000000000..2019ebe94 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,5 @@ +overrides: + - files: "*.md" + options: + proseWrap: never + printWidth: 9999 diff --git a/README.md b/README.md index 20008caa6..11e2bc4f9 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ These crates are provided by the community. | [actix-hash] | [![crates.io](https://img.shields.io/crates/v/actix-hash?label=latest)][actix-hash] [![dependency status](https://deps.rs/crate/actix-hash/latest/status.svg)](https://deps.rs/crate/actix-hash) | Hashing utilities for Actix Web. | | [actix-bincode] | ![crates.io](https://img.shields.io/crates/v/actix-bincode?label=latest) [![dependency status](https://deps.rs/crate/actix-bincode/latest/status.svg)](https://deps.rs/crate/actix-bincode) | Bincode payload extractor for Actix Web | | [sentinel-actix] | ![crates.io](https://img.shields.io/crates/v/sentinel-actix?label=latest) [![dependency status](https://deps.rs/crate/sentinel-actix/latest/status.svg)](https://deps.rs/crate/sentinel-actix) | General and flexible protection for Actix Web | -| [actix-telepathy] | ![crates.io](https://img.shields.io/crates/v/actix-telepathy?label=latest) [![dependency status](https://deps.rs/crate/actix-telepathy/latest/status.svg)](https://deps.rs/crate/actix-telepathy) | Build distributed applications with `RemoteActors` and `RemoteMessages`. | +| [actix-telepathy] | ![crates.io](https://img.shields.io/crates/v/actix-telepathy?label=latest) [![dependency status](https://deps.rs/crate/actix-telepathy/latest/status.svg)](https://deps.rs/crate/actix-telepathy) | Build distributed applications with `RemoteActors` and `RemoteMessages`. | To add a crate to this list, submit a pull request. diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index 757c4a7f1..dea152689 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -125,13 +125,11 @@ - `CorsFactory` is removed. [#119] - The `impl Default` constructor is now overly-restrictive. [#119] - Added `Cors::permissive()` constructor that allows anything. [#119] -- Adds methods for each property to reset to a permissive state. (`allow_any_origin`, - `expose_any_header`, etc.) [#119] +- Adds methods for each property to reset to a permissive state. (`allow_any_origin`, `expose_any_header`, etc.) [#119] - Errors are now propagated with `Transform::InitError` instead of panicking. [#119] - Fixes bug where allowed origin functions are not called if `allowed_origins` is All. [#119] - `AllOrSome` is no longer public. [#119] -- Functions used for `allowed_origin_fn` now receive the Origin HeaderValue as the - first parameter. [#120] +- Functions used for `allowed_origin_fn` now receive the Origin HeaderValue as the first parameter. [#120] [#114]: https://github.com/actix/actix-extras/pull/114 [#118]: https://github.com/actix/actix-extras/pull/118 diff --git a/actix-cors/README.md b/actix-cors/README.md index f5bdc9247..7551215e9 100644 --- a/actix-cors/README.md +++ b/actix-cors/README.md @@ -1,11 +1,69 @@ # actix-cors -> Cross-Origin Resource Sharing (CORS) controls for Actix Web. + [![crates.io](https://img.shields.io/crates/v/actix-cors?label=latest)](https://crates.io/crates/actix-cors) [![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.6.5)](https://docs.rs/actix-cors/0.6.5) -![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-cors) +![Version](https://img.shields.io/badge/rustc-1.68+-ab6000.svg) +![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-cors.svg) +
[![Dependency Status](https://deps.rs/crate/actix-cors/0.6.5/status.svg)](https://deps.rs/crate/actix-cors/0.6.5) +[![Download](https://img.shields.io/crates/d/actix-cors.svg)](https://crates.io/crates/actix-cors) +[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) + + + + + +Cross-Origin Resource Sharing (CORS) controls for Actix Web. + +This middleware can be applied to both applications and resources. Once built, a [`Cors`] builder can be used as an argument for Actix Web's `App::wrap()`, `Scope::wrap()`, or `Resource::wrap()` methods. + +This CORS middleware automatically handles `OPTIONS` preflight requests. + +## Crate Features + +- `draft-private-network-access`: ⚠️ Unstable. Adds opt-in support for the [Private Network Access] spec extensions. This feature is unstable since it will follow breaking changes in the draft spec until it is finalized. + +## Example + +```rust +use actix_cors::Cors; +use actix_web::{get, http, web, App, HttpRequest, HttpResponse, HttpServer}; + +#[get("/index.html")] +async fn index(req: HttpRequest) -> &'static str { + "

Hello World!

" +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + HttpServer::new(|| { + let cors = Cors::default() + .allowed_origin("https://www.rust-lang.org") + .allowed_origin_fn(|origin, _req_head| { + origin.as_bytes().ends_with(b".rust-lang.org") + }) + .allowed_methods(vec!["GET", "POST"]) + .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT]) + .allowed_header(http::header::CONTENT_TYPE) + .max_age(3600); + + App::new() + .wrap(cors) + .service(index) + }) + .bind(("127.0.0.1", 8080))? + .run() + .await; + + Ok(()) +} +``` + +[Private Network Access]: https://wicg.github.io/private-network-access + + ## Documentation & Resources diff --git a/justfile b/justfile index 8c41c8715..d92f09c1e 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,14 @@ _list: @just --list +# Format workspace. +fmt: + npx -y prettier --write $(fd --hidden --extension=yml --extension=md) + +# Update READMEs from crate root documentation. +update-readmes: && fmt + cd ./actix-cors && cargo rdme --force + # Document crates in workspace. doc: RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --all-features