Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS triggered when used locally. #8

Open
jshanab opened this issue Jul 9, 2020 · 1 comment
Open

CORS triggered when used locally. #8

jshanab opened this issue Jul 9, 2020 · 1 comment
Assignees

Comments

@jshanab
Copy link

jshanab commented Jul 9, 2020

I think I need to add a "Access-Control-Allow-Origin: *" header to my response.
I could not see how to add headers.

When I tried it here:
struct Response* responseAllocWithFile(const char* filename, const char* MIMETypeOrNULL) {
struct Response* response = responseAlloc(200, "OK", MIMETypeOrNULL, 0);
response->extraHeaders = strdup("Access-Control-Allow-Origin: *");
response->filenameToSend = strdup(filename);
return response;
}

I broke an already working (in browser with security disabled) json file response.

I really do not understand CORS that much and why when I have a server, the origins do not match. Maybe its a windows thing.

@hellerf hellerf self-assigned this Jul 12, 2020
@hellerf
Copy link
Owner

hellerf commented Jul 12, 2020

Hello,
Thanks for writing in. It looks like I made it so that response->extraHeaders has to contain its own \r\n at the end of each header. This is not documented nor easy to discover. For this case try adding a \r\n like this:

response->extraHeaders = strdup("Access-Control-Allow-Origin: *\r\n");

I also have not much of a clue about CORS.

I'll leave issue open for better documentation, and maybe some better functions around mutating the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants