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

**URL:** <https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092>\
**Category:** Kernel\
**Created:** [March 28, 2018, 6:31pm UTC](https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092 "2018-03-28T18:31:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 28, 2018, 6:31pm UTC](https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092/1 "2018-03-28T18:31:49Z")

</div>

**[derekgn](https://sourceforge.net/u/derekgn/)** wrote on [Wednesday, March 28, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/5f905791/#a05b):

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.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 29, 2018, 6:23pm UTC](https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092/2 "2018-03-29T18:23:08Z")

</div>

**[derekgn](https://sourceforge.net/u/derekgn/)** wrote on [Thursday, March 29, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/5f905791/#d15a):

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.

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

```

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

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [March 30, 2018, 4:27pm UTC](https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092/3 "2018-03-30T16:27:33Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Friday, March 30, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/5f905791/#4bc7):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 31, 2018, 6:53pm UTC](https://forums.freertos.org/t/freertos-tcp-issue-with-prvsendreply-when-returning-status-code-with-no-payload/7092/4 "2018-03-31T18:53:09Z")

</div>

**[derekgn](https://sourceforge.net/u/derekgn/)** wrote on [Saturday, March 31, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/5f905791/#8848):

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