qhttpserver icon indicating copy to clipboard operation
qhttpserver copied to clipboard

cors

Open matzrm opened this issue 7 years ago • 1 comments

how can I add cors information to header?

matzrm avatar Feb 05 '18 16:02 matzrm

Hey, you can do this in the code replying for every endpoint the method OPTIONS:

`

 if (req->method() == qhttp::EHTTP_OPTIONS)
  {
    resp->addHeader("Access-Control-Allow-Origin", "*");

    resp->addHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS");

    resp->addHeader("Access-Control-Allow-Headers", "Content-Type, Origin, Accept, Authorization, Content-Length, X-Requested-With");

    resp->setStatusCode(qhttp::ESTATUS_OK);

    resp->end();

    return;
  }

` and you also have to add the same headers in your replies.

ivancho98 avatar Aug 24 '19 15:08 ivancho98