Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
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).
I am using the hardware module 1LD 43438 with Wiced v6.4.
The communication is done with HTTP request to an Amazon S3 server. But I use only standard, so the result is the same with any http communication with any server.
You can have a look on the function "deferred_receive_handler"and you will clearly see that the double "\r\n\r\n" (defined by HTTP_CRLF_CRLF) is removed as it the header length stop before it and the payload pointer start after it:
if ( find_status_line( (char*) data, fragment_available_data_length, &parsed_data, &parsed_data_length ) == WICED_SUCCESS )
/* Now extract packet payload info such as data, data length, data type and message length */
http_response.payload = (uint8_t*) strnstrn( (char*)data, fragment_available_data_length, HTTP_CRLF_CRLF, sizeof( HTTP_CRLF_CRLF ) - 1 );
/* This will have HTTP header length */
http_response.response_hdr_length = (http_response.payload - data);
/* Payload starts just after the header */
http_response.payload += strlen( HTTP_CRLF_CRLF );
Now, if you look the "http_parse_header"function:
while ( http_get_next_line( (const char*)line, remaining_length, &next_line ) == WICED_SUCCESS )
for ( a = 0; a < number_of_header_fields; a++ )
if ( memcmp( header[a].field, line, header[a].field_length ) == 0 )
if ( http_get_next_string_token( (const char*) line, (uint16_t) ( next_line - line ), ':', &( header[ a ].value ) ) == WICED_SUCCESS )
header[a].value_length = (uint16_t)( next_line - header[ a ].value ) - ( sizeof( HTTP_CLRF ) - 1 );
result = WICED_SUCCESS;
remaining_length -= (uint32_t)( next_line - line );
line = next_line;
the "htt_get_next_line" function is looking for a \r\n to detect each keyword of the HTTP header. As the double \r\n is removed, the last line is never detected.
wiced_result_t http_get_next_line( const char* line, uint16_t max_length, char** next_line )
for ( a = 0; a < max_length - 1; a++ )
if ( ( *( line + a ) == '\r' ) && ( *( line + a + 1 ) == '\n' ) )
*next_line = (char*)line + a + 2;
I think you can easily reproduce this issue with any platform, using the exemple from Cypress Academy WW101 : CypressAcademy_WW101_Files-master\Projects\ww101key\07c\09_aws_get.