mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 02:19:22 +02:00
docs(cors): use cargo-rdme
This commit is contained in:
@ -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
|
||||
|
@ -1,11 +1,69 @@
|
||||
# actix-cors
|
||||
|
||||
> Cross-Origin Resource Sharing (CORS) controls for Actix Web.
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-cors)
|
||||
[](https://docs.rs/actix-cors/0.6.5)
|
||||

|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-cors/0.6.5)
|
||||
[](https://crates.io/crates/actix-cors)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- cargo-rdme start -->
|
||||
|
||||
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 {
|
||||
"<p>Hello World!</p>"
|
||||
}
|
||||
|
||||
#[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
|
||||
|
||||
<!-- cargo-rdme end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
|
Reference in New Issue
Block a user