FreeRTOS+TCP issue with prvSendReply when returning status code with no payload

derekgn wrote on Wednesday, March 28, 2018:

I am working on an embedded rest api based on the FreeRTOS+TCP Labs Build 160919 http server. While I am waiting on the hardware for the project I am running my code under the windows simulator.

I have observed an issue with the method prvSendReply method. Basically when code returns a 404 (not found) the browser timesout. This also occurs when there is any

This is easy to reproduce by running the FreeRTOS_Plus_TCP_and_FAT_Windows_Simulator code and requesting a non existant file for example freertos.htmlx

I have run a network trace and I can see the http response packets being transmitted and acked. It appears that there is something specific to the contents of the response that the browser does not like.

I have used IE, firefox, chrome and all exhibit the same issue.

I have modified the response to use content lenght header, connection close etc but have been unable to prevent the browser timeout. I am looking for any pointers as to what the problem might be and how to resolve as for my project I will be returing status codes only for a number of api calls.


derekgn wrote on Thursday, March 29, 2018:

For anyone interested there is a bug in FreeRTOS_HTTP_server.c
The Content-Length header is not set when a http response code is being returned that has no content.

Browsers seem to have an issue with this payload it looks like they are waiting for more content.

Adding the content Content-Length header with a value of 0 prior to the call to prvSendReply @Line 308 in FreeRTOS_HTTP_server.c for FreeRTOS+TCP Labs Build 160919 will resolve the browser hang.

if( pxClient->pxFileHandle == NULL )
    strcpy( pxClient->pxParent->pcExtraContents, "Content-Length: 0\r\n" );
    /* "404 File not found". */
    xRc = prvSendReply( pxClient, WEB_NOT_FOUND );
    pxClient->uxBytesLeft = ( size_t ) pxClient->pxFileHandle->ulFileSize;
    xRc = prvSendFile( pxClient );

Also the Content-Length header must be post fixed with \r\n

heinbali01 wrote on Friday, March 30, 2018:

Hi Derek, sorry for my late response. I’m travelling around till next week.
Thanks a lot for reporting this. Sounds plausible that a content length of zero must be transmitted.

derekgn wrote on Saturday, March 31, 2018:

Hey no problem. It did’nt take too long to figure out.