rocket_cors/CHANGELOG.md

2.7 KiB

CHANGELOG

0.5.2 (2020-03-18)

Improvements

  • Add a builder methods for CorsOptions (#75)

0.5.1 (2019-11-13)

There are no new features.

  • Fix build issues with Rocket 0.4.2
  • Fix clippy lints with latest nightly

0.5.0 (2019-05-27)

There is no change since 0.5.0-beta1.

Breaking Changes

  • The Cors struct can no longer be constructed. Instead, you will now construct the options for Cors directly or through deserialization using the CorsOptions struct. Then, you can construct Cors for use in Fairings or manual responses using the CorsOptions::to_cors method.
  • The AllowedOrigins type has been modified. It is now a typedef of AllOrSome<Origins> where Origins is now a struct supporting exact matches or regex matches.

Migrating existing Code

  • Existing use of AllowedOrigins::some to create exact matches can be replaced simply with AllowedOrigins::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 method

    -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(())
    }