Expand description
Library adds CORS protection for Salvo web framework.
§Example
use salvo_core::http::Method;
use salvo_core::prelude::*;
use salvo_cors::Cors;
let cors_handler = Cors::new()
.allow_origin("https://salvo.rs")
.allow_methods(vec![Method::GET, Method::POST, Method::DELETE]).into_handler();
let router = Router::new().hoop(cors_handler).post(upload_file).options(upload_file);
#[handler]
async fn upload_file(res: &mut Response) {
}
If you want to allow any router:
use salvo_core::prelude::*;
use salvo_cors::{self as cors, Cors};
let cors_handler = Cors::new().allow_origin(cors::Any).into_handler();
Read more: https://salvo.rs
Structs§
- Holds configuration for how to set the
Access-Control-Allow-Credentials
header. - Holds configuration for how to set the
Access-Control-Allow-Headers
header. - Holds configuration for how to set the
Access-Control-Allow-Methods
header. - Holds configuration for how to set the
Access-Control-Allow-Origin
header. - Represents a wildcard value (
*
) used with some CORS headers such asCors::allow_methods
. - CorsHandler
- Holds configuration for how to set the
Access-Control-Expose-Headers
header. - Holds configuration for how to set the
Access-Control-Max-Age
header. - Holds configuration for how to set the
Vary
header.
Enums§
- Enum to control when to call next handler.
Functions§
- Iterator over the three request headers that may be involved in a CORS preflight request.