[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [patch #9668] Add custom 404 handler to HTTP server

From: Johan Borkhuis
Subject: [lwip-devel] [patch #9668] Add custom 404 handler to HTTP server
Date: Wed, 4 Jul 2018 04:14:06 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36


                 Summary: Add custom 404 handler to HTTP server
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: borkhuis
            Submitted on: Wed 04 Jul 2018 08:14:04 AM UTC
                Category: apps
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None



The current implementation of the webserver (in src/apps/httpd) expects that
each URL refers to a file (in fsdata).

For my implementation I would like to have a representation of a local file
system, but this means that the provided URL does not match a file in the
HTTPD files (as part of the fsdata). 

For example, the URL i want to use is http://<server>/files/, but this would
result in a 404. Next to serving a directory overview I would also like the
option of downloading files directly from the directory, more like for example
Apache does.

To implement this I have added an option to the HTTPD configuration
(LWIP_HTTPD_CUSTOM_404_HANDLER). When this is defined a user callback function
(http_custom_404_handler) is called. If this function returns ERR_OK the data
provided by this function will be sent back to the client, otherwise the
normal 404 page will be served. Using this method I am able to very easily
create a /files/-handler, that can server a directory overview, but also
allows for downloading of files.

Note that the data provided by the callback function should include all
Next to the way I am using this method, this also allows for users to create
additional return codes (like a 418), as all the headers need to be provided
by the callback.

The patch is based on the STABLE-2.0.3_RELEASE.


File Attachments:

Date: Wed 04 Jul 2018 08:14:04 AM UTC  Name: httpd.patch  Size: 3KiB   By:



Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]