This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LWIP HTTPd sends two headers

Other Parts Discussed in Thread: TM4C1294NCPDT

I noticed that when I was working with my TM4C1294NCPDT enet_lwip example, that I'd get a response header on the top of my web page if I pulled the web page down a second time (and all successive times).  This doesn't happen the first time, strangely enough.  I cracked open my Wireshark and grabbed a capture.  What do you know, it seems like the HTTP/1.0 OK response header is duplicated twice; once each by two different versions of the software...
I suspect this is not a bug in the TI implementation, it's probably a bug in the LWIP HTTPd itself.   The issue here is that it completely blows away the functionality of the <head> tag, along with any CSS and Javascript that I want running.  Here's a snippet of what I got from wireshark:

GET / HTTP/1.1

Host: 192.168.1.21

User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

DNT: 1

Connection: keep-alive

Cache-Control: max-age=0




HTTP/1.0 200 OK

Server: lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip)

Content-type: text/html



HTTP/1.0 200 OK

Server: lwIP/1.3.2 (http://www.sics.se/~adam/lwip/)

Content-type: text/html

...  Normal HTML continues from here.

This isn't going to stop me from doing anything, and I can certainly sniff out and snuff out the offending header-producer, however, I figured you guys ought to know about it.

Thank  you,

Rob

  • Ok, this is happening because there's a broad spectrum of mishandling of the value fsdata_file::http_header_included in the lwIP base code.  First, that value is not set by makefsfile.c in the makefsfile tool.   To do this properly, you need to make the following change:


    @@ -1684,12 +1681,13 @@ main(int argc, char *argv[])
                         fprintf(g_fhOutput, "const struct fsdata_file file%s[] =\n",
                                 pFileInfo->pszStructName);
                         fprintf(g_fhOutput,
    -                            "{\n\t{\n\t\t%s%s,\n\t\tdata%s,\n\t\tdata%s + %ld,\n\t\tsizeof(data%s) - %ld\n\t}\n};\n\n",
    +                            "{\n\t{\n\t\t%s%s,\n\t\tdata%s,\n\t\tdata%s + %ld,\n\t\tsizeof(data%s) - %ld,\n\t\t%d\n\t}\n};\n\n",
                                 (pszPrevious ? "file" : ""),
                                 (pszPrevious ? pszPrevious : "NULL"),
                                  pFileInfo->pszStructName,
                                  pFileInfo->pszStructName, lSize,
    -                             pFileInfo->pszStructName, lSize);
    +                             pFileInfo->pszStructName, lSize,
    +                               g_bExcludeHeaders?0:1);

                         //
                         // Update the binary size.

    This change should gracefully differentiate if you turn on ExcludeHeaders.

    Then, this value needs to be propagated by the enet_fs.c file.  The data in this structure is copied when this entry is opened in the filesystem, at approx line 200, and this value needs to be copied as well:


                //
                // We are not using any file system extensions in this
                // application, so set the pointer to NULL.
                //
                psFile->pextension = NULL;

    +          psFile->http_header_included = psTree->http_header_included;
                //
                // Exit the loop and return the file system pointer.
                //
                break;
            }

    Also, this function opens things on the fatFS, so we'll need to make sure that value is set to zero here.  We're basically assuming that all files in the fatFS don't come with HTTP response headers at the top  (approx line 150):


            //
            // Attempt to open the file on the Fat File System.
            //
            fresult = f_open(psFatFile, pcName + 3, FA_READ);
            if(fresult == FR_OK)
            {
                psFile->data = NULL;
                psFile->len = 0;
                psFile->http_header_included = 0;
                psFile->index = 0;
                psFile->pextension = psFatFile;
                return(psFile);
            }



    Have fun!

    Rob