issue with HTTP client Header parser

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaCa_2922036
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hello,
I met an issue with the lib http and http_client with the function which get the Http answer received after sending a HTTP GET request:

The function callback "deferred_receive_handler" (in /libraries/protocols/HTTP_clent/http_client.c):
manage the copy of received TCP data into buffers. One buffer for the header part, and another for the payload. The function detect the separation of the header and the payload with a double "\r\n" sequence. Copy the part before into the header buffer, and the part after into the payload buffer. The double caracters "\r\n" is not saved in the header neither payload buffer.

The function "http_parse_header" (in /libraries/protocols/HTTP_clent/http.c):
it parse the keyword of the header by detecting the characters "\r\n".
=> So, the last keyword of the header is never detected has the buffer is not terminated by the "\r\n" (as removed by the deferred_receive_handler function).

Concretely, if I am looking for a keyword of the header which is positionned at the last keyword, it is never detected! And unfortunately, the keyword order is managed by the server and I can't modify it.

It is a known issue ? is there is patch of something for that ?
I can modify the lib function to avoid that but I am surprised that nobody meet this issue before.
In addition, I am very surprised as this method is the recommanded usage, found in the exemple Cypress Academy WW101 (CypressAcademy_WW101_Files-master\Projects\ww101key\07c\09_aws_get).

Thanks

0 Likes
1 Solution
SChaudeurge
Level 2
Level 2
5 replies posted 5 sign-ins First solution authored

I had the confirmation of Wiced technical support that this issue is a bug from the HTTP_client lib.

The following patch has been validated to correct this bug:

from the file http_client.c, just invert the position of lines 505-506 with lines 508-509:

/***** Patch lib :
* just invert the 2 lines of code
* => instead of removing the "HTTP_CRLF_CRLF" from the Header and Payload,
* keep one HTTP_CRLF in the Header size (and keep removing both HTTP_CRLF_CRLF from the payload). By this way, the http parser will be able to detect the last keyword
* as it need a \r\n to detect a new line
* */

/* Payload starts just after the header */
http_response.payload += strlen( HTTP_CRLF_CRLF );

/* This will have HTTP header length */
http_response.response_hdr_length = (http_response.payload - strlen(HTTP_CLRF) - data); // Keep only \r\n in the header (not double \r\n, otherwise the "http_parse_header" function remaining_length will have value 2. And it will continue parsing the next line and can read the data part as header, which is wrong.
/***** ENF OF THE PATCH  **************/

 

View solution in original post

15 Replies