buglwIP - A Lightweight TCP/IP stack - Bugs: bug #58223, Web server returns HTTP status...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #58223: Web server returns HTTP status code 200 instead of 404 when LWIP_HTTPD_DYNAMIC_HEADER is enabled

Submitter:  Marco Lazzaroni <marcolazzaroni>
Submitted:  Tue 21 Apr 2020 08:31:33 PM UTC
   
 
Category:  apps Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Fixed
Privacy:  Public Assigned to:  kleshov
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Tue 26 Jan 2021 04:26:10 PM UTC, comment #1: 

This bug was introduced by a recent commit that was supposed to fix another bug (56290). I can see no problems with the fix that you are proposing. Pushing it to repo.
Thanks for reporting.

Mike Kleshov <kleshov>
Group Member
Tue 21 Apr 2020 08:31:33 PM UTC, original submission:  

As per object, I get a HTTP 200 status code when doing a GET of a missing page.

LWIP version is last release got with git clone.
I have prepared a 404.html page with this source code:

<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf8">
</head>
<body>
<h1>404 Not Found</h1>
</body>
</html>


In my lwipopts.h I have

#define LWIP_HTTPD_DYNAMIC_HEADERS 1

I generate the fsdata_custom.c file with

makefsdata html -e -f:fsdata_custom.c

(so the headers are not included twice)

What I get when doing a GET of a missing page is wrong (it returns HTTP 200 status code):


lavoro@saiga:~$ curl -i http://192.168.1.9/any_missing_page.html
HTTP/1.0 200 OK
Server: lwIP/2.2.0d (http://savannah.nongnu.org/projects/lwip)
Content-Type: text/html

<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf8">
</head>

<body>
<h1>404 Not Found</h1>
</body>
</html>


If I set LWIP_HTTPD_DYNAMIC_HEADERS to 0 and generate fsdata_custom.c removing the -e switch (makefsdata html -e -f:fsdata_custom.c), the response is correct:

lavoro@saiga:~$ curl -i http://192.168.1.9/any_missing_page.html
HTTP/1.0 404 File not found
Server: lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip)
Content-type: text/html

<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf8">
</head>

<body>
<h1>404 Not Found</h1>
</body>
</html>


I suppose that the problem is that, with LWIP_HTTPD_DYNAMIC_HEADERS at 1, this piece of code in get_http_headers()


if (strstr(uri, "404.") == uri) {
hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_NOT_FOUND];
}

...does not behave as expected because while debugging I saw that uri equals "/404.html" and not "404.html", so the if condition is not true. I think that changing that line to


if (strstr(uri, "/404.") == uri) {


(and the same for 400 an 501) would be enough; I've tested and it works:

lavoro@saiga:~$ curl -i http://192.168.1.9/any_missing_page.html
HTTP/1.0 404 File not found
Server: lwIP/2.2.0d (http://savannah.nongnu.org/projects/lwip)
Content-Type: text/html

<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf8">
</head>

<body>
<h1>404 Not Found</h1>
</body>
</html>

but I'm not sure whether is correct in all possible cases (I mean, all the possible #define combinations supported by LWIP).

Marco Lazzaroni <marcolazzaroni>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kleshov (Posted a comment)
  • -email is unavailable- added by marcolazzaroni (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-01-26 kleshov StatusNone Fixed
        Assigned toNone kleshov
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code