Skip to content

CORS blocking only POST method #2510

Discussion options

You must be logged in to vote

Since the browser does a CORS preflight request with a HTTP OPTIONS method (Read more here: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request). You need to handle that accordingly.

#[macro_use]
extern crate rocket;

use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::{Header, self, Status};
use rocket::response::content;
use rocket::{Request, Response};

pub struct CORS;

#[rocket::async_trait]
impl Fairing for CORS {
    fn info(&self) -> Info {
        Info {
            name: "Add CORS headers to responses",
            kind: Kind::Response,
        }
    }

    async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) {

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thexeromin
Comment options

Answer selected by thexeromin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage A bug report being investigated
2 participants
Converted from issue

This discussion was converted from issue #2509 on March 31, 2023 18:16.