lawliet89 / rocket_cors

Cross-origin resource sharing (CORS) for Rocket.rs applications

Home Page:https://lawliet89.github.io/rocket_cors/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a builder pattern to CorsOptions

morbatex opened this issue · comments

If I'm not mistaken there are two ways right now if one wants to create CorsOptions which differ in some fields from the default option:

let cors_options = CorsOptions{ allow_credentials: true, max_age: Some(100), ..Default::default() };

or

let mut cors_options = CorsOptions::default();
cors_options.allow_credentials = true;
cors_options.max_age = Some(100);

Since the first variant (in my experience) is hardly used at all and the second one is very cumbersome, I would suggest a build pattern so that one could use the following code:

let cors_options = CorsOptions::default().allow_credentails(true).max_age(Some(100));

If you agree with this change, I would implement it and then open a Pull Request.

I personally use option 1, but I am open to making a new builder type too. If you are free to do so, please go ahead and open a PR. All contribution are welcomed!

Fixed by #75