cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Studio Wi-Fi Combo

MaCa_2922036
New Contributor II

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
4 Replies
AditiB_81
Moderator
Moderator

Hi,

Are you using any standard AnyCloud example or have developed a custom example? If custom then please provide us the project details. Also, provide us some pointers to reproduce this issue at our end.

Thanks

Aditi

0 Likes
MaCa_2922036
New Contributor II

Hello,

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 )
{
   uint32_t a;

   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 )
{
    uint32_t a;

    for ( a = 0; a < max_length - 1; a++ )
    {
        if ( ( *( line + a ) == '\r' ) && ( *( line + a + 1 ) == '\n' ) )
        {
            *next_line = (char*)line + a + 2;
            return WICED_SUCCESS;
        }
    }

    return WICED_NOT_FOUND;
}

 

 

 

 

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.

0 Likes
MaCa_2922036
New Contributor II

Here is an exemple of what I receive from the server (http response):

 

HTTP/1.1 206 Partial Content[CR][LF]
x-amz-id-2: bv4B8TitzS84pSyIlzKRJoipeBz+5rhwYRb5FWTCrfRIKNwc1c/4R5hkSWldxtXko7DTBErJxz8=[CR][LF]
x-amz-request-id: D0MZVDT6MQVEVKK3[CR][LF]
Date: Mon, 12 Jul 2021 15:13:06 GMT[CR][LF]
Last-Modified: Mon, 07 Jun 2021 13:22:29 GMT[CR][LF]
ETag: "866bd984f7949ecc5d5a7b89576ff07f"[CR][LF]
x-amz-server-side-encryption: AES256[CR][LF]
x-amz-version-id: H41RnyEXAT0Dxwx8nGqnUz6wuJN0VRs2[CR][LF]
Accept-Ranges: bytes[CR][LF]
Content-Range: bytes 18839344-18839344/18839344[CR][LF]
Content-Type: binary/octet-stream[CR][LF]
Server: AmazonS3[CR][LF]
Content-Length: 1024[CR][LF]
[CR][LF]
0xaa,0xab,0xac, etc...

 

after the reception callback the message is splitted into Header buffer and Payload buffer:

Header:

 

HTTP/1.1 206 Partial Content[CR][LF]
x-amz-id-2: bv4B8TitzS84pSyIlzKRJoipeBz+5rhwYRb5FWTCrfRIKNwc1c/4R5hkSWldxtXko7DTBErJxz8=[CR][LF]
x-amz-request-id: D0MZVDT6MQVEVKK3[CR][LF]
Date: Mon, 12 Jul 2021 15:13:06 GMT[CR][LF]
Last-Modified: Mon, 07 Jun 2021 13:22:29 GMT[CR][LF]
ETag: "866bd984f7949ecc5d5a7b89576ff07f"[CR][LF]
x-amz-server-side-encryption: AES256[CR][LF]
x-amz-version-id: H41RnyEXAT0Dxwx8nGqnUz6wuJN0VRs2[CR][LF]
Accept-Ranges: bytes[CR][LF]
Content-Range: bytes 18839344-18839344/18839344[CR][LF]
Content-Type: binary/octet-stream[CR][LF]
Server: AmazonS3[CR][LF]
Content-Length: 1024

 

and payload:

 

0xaa,0xab,0xac, etc...

 

As you can see, the last header keyword is not terminated by a [CR][LF] so, if I execute the function http_parse_header to looking for the last keyword it return a WICED_NOT_FOUND error.

 

 

parse_header.field = "Content-Length: ";
parse_header.field_length = sizeof("Content-Length: ")-1;
parse_header.value = NULL;
parse_header.value_length = 0;
result = http_parse_header(response->response_hdr,response->response_hdr_length,parse_header, 1); // Parse headers to get the content length
if (result == WICED_SUCCESS)
{
   // never reach here !!!
}

 

 

 

0 Likes
MaCa_2922036
New Contributor II

Does anyone have any answer ?

1 week after the ticket is opened ...

Thank you.

 

0 Likes