forked from lda/telodendria
Spec: Implement CORS
This commit is contained in:
parent
1d0c48ce32
commit
184866532a
1 changed files with 22 additions and 3 deletions
21
src/Matrix.c
21
src/Matrix.c
|
@ -54,15 +54,34 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
|||
}
|
||||
LogConfigUnindent(lc);
|
||||
|
||||
|
||||
HttpResponseStatus(context, HTTP_OK);
|
||||
HttpResponseHeader(context, "Server", "Telodendria v" TELODENDRIA_VERSION);
|
||||
HttpResponseHeader(context, "Content-Type", "application/json");
|
||||
|
||||
/* CORS */
|
||||
HttpResponseHeader(context, "Access-Control-Allow-Origin", "*");
|
||||
HttpResponseHeader(context, "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||
HttpResponseHeader(context, "Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Authorization");
|
||||
|
||||
/*
|
||||
* Web Browser Clients: Servers MUST expect that clients will approach them
|
||||
* with OPTIONS requests... the server MUST NOT perform any logic defined
|
||||
* for the endpoints when approached with an OPTIONS request.
|
||||
*/
|
||||
if (HttpRequestMethodGet(context) == HTTP_OPTIONS)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_NO_CONTENT);
|
||||
HttpSendHeaders(context);
|
||||
|
||||
goto finish;
|
||||
}
|
||||
|
||||
HttpSendHeaders(context);
|
||||
stream = HttpStream(context);
|
||||
fprintf(stream, "{}\n");
|
||||
|
||||
finish:
|
||||
stream = HttpStream(context);
|
||||
fclose(stream);
|
||||
|
||||
LogConfigUnindent(lc);
|
||||
|
|
Loading…
Reference in a new issue