From d707ad7b7aaf3e0a5ca1647e5ac604ec59eeafbe Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Mon, 18 Mar 2019 10:27:56 +0800 Subject: [PATCH] Add CHANGELOG and migration notes --- CHANGELOG.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2241c09 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,58 @@ +# CHANGELOG + +## 0.5.0 (Unreleased) + +### Breaking Changes + +- The [`Cors`](https://lawliet89.github.io/rocket_cors/rocket_cors/struct.Cors.html) struct can no + longer be constructed. Instead, you will now construct the options for Cors directly or through + deserialization using the + [`CorsOptions`](https://lawliet89.github.io/rocket_cors/rocket_cors/struct.CorsOptions.html) + struct. Then, you can construct `Cors` for use in Fairings or manual responses using the + [`CorsOptions::to_cors`](https://lawliet89.github.io/rocket_cors/rocket_cors/struct.CorsOptions.html#method.to_cors) + method. +- The + [`AllowedOrigins`](https://lawliet89.github.io/rocket_cors/rocket_cors/type.AllowedOrigins.html) + type has been modified. It is now a typedef of `AllOrSome` where + [`Origins`](https://lawliet89.github.io/rocket_cors/rocket_cors/struct.Origins.html) is now + a struct supporting exact matches or regex matches. + +### Migrating existing Code + +- Existing use of + [`AllowedOrigins::some`](https://docs.rs/rocket_cors/0.4.0/rocket_cors/type.AllowedOrigins.html#method.some) + to create exact matches can be replaced simply with + [`AllowedOrigins::some_exact`](https://lawliet89.github.io/rocket_cors/rocket_cors/type.AllowedOrigins.html#method.some_exact) + instead. +- Replace all construction of `Cors` struct with `CorsOptions` instead. Then, you can create the + `Cors` struct for use in Fairings using the + [`CorsOptions::to_cors`](https://lawliet89.github.io/rocket_cors/rocket_cors/struct.CorsOptions.html#method.to_cors) + method + + ```diff + -fn main() { + +fn main() -> Result<(), Error> { + let (allowed_origins, failed_origins) = AllowedOrigins::some(&["https://www.acme.com"]); + assert!(failed_origins.is_empty()); + + // You can also deserialize this + - let options = rocket_cors::Cors { + + let cors = rocket_cors::CorsOptions { + allowed_origins: allowed_origins, + allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), + allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), + allow_credentials: true, + ..Default::default() + - }; + + } + + .to_cors()?; + + rocket::ignite() + .mount("/", routes![cors]) + - .attach(options) + + .attach(cors) + .launch(); + + + + Ok(()) + } + ```