patchlwIP - A Lightweight TCP/IP stack - Patches: patch #9668, Add custom 404 handler to HTTP...

 
 

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

patch #9668: Add custom 404 handler to HTTP server

Submitter:  Johan Borkhuis <borkhuis>
Submitted:  Wed 04 Jul 2018 08:14:04 AM UTC
   
 
Category:  apps Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Planned Release:  None

Wed 04 Jul 2018 02:01:02 PM UTC, comment #2: 

Simon,
I attached a new patch file, now based on the git master, just for reference. The change itself is quite small, and only impacts the 404 handler.
But if this is not the right time for this change then just let it go, and I will have a look again when 2.1.0 is released, to see if it is still needed, or if there is another way to achieve this.

(file #44505)

Johan Borkhuis <borkhuis>
Wed 04 Jul 2018 01:01:36 PM UTC, comment #1: 

Please base patches on git master, not on 2.0.3. Chances are that they don't apply any more and manual rebase is no fun.

Next, I want to restructure the 'fs' module and we need to restructure the integration of ssi and cgi so that we have more control about generated headers. Being like that, what you want to do might work in the end, but I don't think after those changes, your patch applies cleanly...

However, all that has to wait until 2.1.0 is released.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 04 Jul 2018 08:14:04 AM UTC, original submission:  

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 headers.
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.

Johan Borkhuis <borkhuis>

 

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

Attached Files
file #44505:  httpd.patch added by borkhuis (3KiB - application/octet-stream - Patch now based on GIT master)
file #44504:  httpd.patch added by borkhuis (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by borkhuis (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-04 borkhuis Attached File- Added httpd.patch, #44505
    2018-07-04 borkhuis Attached File- Added httpd.patch, #44504

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code