STM32CubeU5
STM32CubeU5 copied to clipboard
IOT_HTTP_WebServer application does not send HTTP headers as intended
Describe the set-up
- B-U585I-IOT02A board
- STM32CubeIDE Version: 1.9.0
Describe the bug
The IOT_HTTP_WebServer application does not send HTTP headers as intended.
How to reproduce the bug
- Run the IOT_HTTP_WebServer application on the B-U585I-IOT02A board.
- Open the "STM32U5 Webserver Demo" website in Chrome.
- Open the Chrome developer tools and examine the HTTP headers, for example for "chunk.css".
- There is no "Response Headers" section present while according to the source code "text/css" should be present as "Content-Type" header, and there should be additional HTTP headers:

Compare that to the response for "chunk.js" which has "Response Headers" including "Content-Type: text/javascript":

That "chunk.js" has the HTTP headers is purely by coincidence as explained below.
Additional context
The problem is caused by the fact that two parameters are passed in the wrong order whenhttp_send_response() calls http_send_headers_response():
https://github.com/STMicroelectronics/STM32CubeU5/blob/133d940e5bd3a38955b9ba0cdf316f9681d0af2d/Projects/B-U585I-IOT02A/Demonstrations/IOT_HTTP_WebServer/WebServer/App/http/webserver_http_response.c#L243-L276
Note the call http_send_headers_response(headers_id, socket, headers_buff, data_size), while the signature of http_send_headers_response is http_send_headers_response(uint32_t socket, uint32_t headers_id, ...). The parameters headers_id and socket are passed in the wrong order.
This also explains why the headers for the JavaScript file is sent. It works by accident because the socket id is 1 and because HTTP_HEADER_JS_ID is defined as 1.
The following patch fixes the problem:
diff --git a/Projects/B-U585I-IOT02A/Demonstrations/IOT_HTTP_WebServer/WebServer/App/http/webserver_http_response.c b/Projects/B-U585I-IOT02A/Demonstrations/IOT_HTTP_WebServer/WebServer/App/http/webserver_http_response.c
index dcaf97fd..d04f6251 100644
--- a/Projects/B-U585I-IOT02A/Demonstrations/IOT_HTTP_WebServer/WebServer/App/http/webserver_http_response.c
+++ b/Projects/B-U585I-IOT02A/Demonstrations/IOT_HTTP_WebServer/WebServer/App/http/webserver_http_response.c
@@ -247,7 +247,7 @@ static WebServer_StatusTypeDef http_send_response(uint32_t headers_id,
uint32_t data_size)
{
/* Send HTTP header response */
- if (http_send_headers_response(headers_id, socket, headers_buff, data_size) != WEBSERVER_OK)
+ if (http_send_headers_response(socket, headers_id, headers_buff, data_size) != WEBSERVER_OK)
{
return HTTP_ERROR;
}
With that patch applied the HTTP headers are sent as expected for all elements.
ST Internal Reference: 126694
Hi @smuehlst,
Thank you for your contribution. This issue has been fixed in the frame of version v1.2.0 of the STM32CubeU5. Please allow me then to close this thread.
With regards,