2024-03-14 10:34 AM
Hi - can anyone tell me how to insert a CORS header into LWIP?
(Cross-Origin Resource Sharing) header directly into the httpd.c? file of LwIP)
i.e.Access-Control-Allow-Origin: *
I am using vscode to debug an index.shtml file file, but i need to get responses from my H743 webserver to be able to debug fully.
Any ideas?
Thanks
Chris
2024-03-14 10:47 AM
From https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS it looks like they're just standard HTTP headers ?
2024-03-15 02:54 AM
Thanks Andrew,
Thats quite interesting - but I'm trying to find out where and how to insert these headers into the LWIP response CODE. I have found various places, but none of my attempts appear to work.
Unfortunately, I am not an expert in LWIP webserver code and I do not have weeks of time to spare!
Chris
2024-03-15 03:16 AM
neither am I.
But, given they're just ordinary HTTP headers, then inserting them should should be the as inserting any other headers?
2024-03-15 06:30 AM
Apparently, you cant just add CORS headers directly to the HTML file.
I'm trying to find exactly where in the LWIP (perhaps httpd.c) code I can add them!
2024-03-15 06:53 AM
That doesn't sound right: HTTP is a transport protocol - HTML is a payload format.
:thinking_face:
2024-03-15 07:36 AM
From what I've deduced from searching, the way to dynamically add the CORS header into LWIP is somewhere in the httpd.c file.
But where and how?
2024-03-22 03:24 AM
Hello!
I am facing the same problem! I think we need to add the CORS policy headers in this section:
static const char *const g_psHTTPHeaderStrings[] = {
"HTTP/1.0 200 OK\r\n",
"HTTP/1.0 404 File not found\r\n",
"HTTP/1.0 400 Bad Request\r\n",
"HTTP/1.0 501 Not Implemented\r\n",
"HTTP/1.1 200 OK\r\n",
"HTTP/1.1 404 File not found\r\n",
"HTTP/1.1 400 Bad Request\r\n",
"HTTP/1.1 501 Not Implemented\r\n",
"Content-Length: ",
"Connection: Close\r\n",
"Connection: keep-alive\r\n",
"Connection: keep-alive\r\nContent-Length: ",
"Server: "HTTPD_SERVER_AGENT"\r\n",
// Add CORS headers
"Access-Control-Allow-Origin: *\r\n",
"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n",
"Access-Control-Allow-Headers: Content-Type\r\n",
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
#if LWIP_HTTPD_SUPPORT_11_KEEPALIVE
, "Connection: keep-alive\r\nContent-Length: 77\r\n\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
#endif
};
But there is something missing.
Let me know if you find any solution.
2024-03-22 03:37 AM
Hi Jp - i've tried that already - makes no difference. I need to do a bit (lot) of studying!!
Good Luck!