recycled-air / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Feature req: 404 page #48

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Might seems like a silly request, but would it be possible to implement a 
directive that specifies a file to serve instead of the current 
"Error xxx: mmmm\ntttttt" error message for some of the error codes for 
which it makes sense (eg: 404, 403, 401, 500, 503, etc)?

What version of the product are you using? On what operating system?
  mongoose-2.6 on WinXP MCE 2k2

Original issue reported on code.google.com by roza.cho...@gmail.com on 22 May 2009 at 7:27

GoogleCodeExporter commented 8 years ago
Poking through the embedding API, I noticed mg_bind_to_error_code().

Perhaps this is already the framework for the feature to be added. 

Add an option to the program for specifying a file to respond with per code, 
and 
then process the option by registering a handler that feeds back the specified 
file, 
and implement the current behaviour as a default should the specified file not 
exist 
or not be available for serving.

Original comment by roza.cho...@gmail.com on 22 May 2009 at 8:17

GoogleCodeExporter commented 8 years ago

Original comment by valenok on 22 May 2009 at 9:18

GoogleCodeExporter commented 8 years ago
If it isn't too difficult, add a new config option to specify a file to serve 
when
any HTTP error happens (not only 404 but 403 and maybe others). When Mongoose 
calls
the error file (which can be CGI), it should pass the error code as 
REDIRECT_STATUS
in the HTTP header. If you want to pass additional, human-readable, 
information, it
can go in the REDIRECT_ERROR_NOTES header.

Original comment by googl...@springtimesoftware.com on 23 May 2009 at 1:22

GoogleCodeExporter commented 8 years ago
The idea is to have a command line option, like:
-error_file 404=404.html,....,0=generic_error.html
For any error code, a file name may be specified. Error code 0 matches any 
error.
And yes, it is a good idea to send those REDIRECT_* headers too.

Original comment by valenok on 23 May 2009 at 5:15

GoogleCodeExporter commented 8 years ago
I hope when you mentioned a command line option that you would also implement 
it in
the configuration file.

Your approach seems fine to me, although what I had in mind was a "catch-all" 
file
that would handle ANY error, not just those listed in the directive.

Example: -error_file any=error.php

This would serve file error.php, passing it the error information as discussed 
above.

Of course, your idea is better when the user has no CGI interpreter installed. 
Can we
please have both?

Original comment by googl...@springtimesoftware.com on 23 May 2009 at 5:39

GoogleCodeExporter commented 8 years ago

  -error_file 404=404.html,0=error.php

0 means wildcard, i.e. all errors that are not listed explicitely will match it.
Also, Mongoose will handle error files according to the file extensions.

For example, with the aboce option, on "500 Internal Server Error" Mongoose 
will show
error.php. Is this be behaviour you are talking about?

Original comment by valenok on 23 May 2009 at 5:51

GoogleCodeExporter commented 8 years ago
Yes, perfect. Thank you!

By the way, I took a fast look at your code. It's excellent. Good error 
checking. I
like your use of "cry" for error handling. The world is lucky you are making 
this.

Original comment by googl...@springtimesoftware.com on 23 May 2009 at 6:26

GoogleCodeExporter commented 8 years ago
But this has been open since May, and not marked "blocked on"...

Original comment by googl...@springtimesoftware.com on 4 Sep 2010 at 4:07

GoogleCodeExporter commented 8 years ago

Original comment by valenok on 21 Jun 2011 at 9:11

GoogleCodeExporter commented 8 years ago
any progress on this issue? Would be very useful for my little project AdAway 
(http://code.google.com/p/ad-away)

I am blocking advertisements on android with the hosts file and have bundled 
your webserver to answer request locally to servers that are redirected to 
127.0.0.1

When for example a hostname in the hosts file that serves ads is redirected to 
127.0.0.1 and a website has an iframe with ads in it. There will be an error 
that this iframe can not be loaded. I would like to provide a blank page with 
mongoose instead. For this I could use custom 404 error pages.

Thanks for this wonderful project!

Original comment by domschuermann@gmail.com on 30 Sep 2011 at 8:33

GoogleCodeExporter commented 8 years ago
@10

plus one

Why can not image requests be answered with an image and document requests be 
answered with a document?

Original comment by marjorly...@gmail.com on 6 Oct 2011 at 12:14

GoogleCodeExporter commented 8 years ago
Implemented my idea for AdAway using a modified hello.c from the examples. This 
feature requests is no longer important for me.

Thanks for making this webserver.

Original comment by domschuermann@gmail.com on 8 Nov 2011 at 1:27

GoogleCodeExporter commented 8 years ago
Implemented in the clone at 
https://github.com/GerHobbelt/mongoose/commit/2d37215959dd27363b8be2dd9ab45de0ff
719d54

fix for issue 48: custom error pages. Supports -error_file directory as per 
http://code.google.com/p/mongoose/issues/detail?id=48#c6 . Error files are 
served via the generic mg_produce_nested_page() API - done that way so custom 
event callbacks can (re)use the same logic. Since mg_produce_nested_page() uses 
the internal handle_request() mongoose page serving engine, support for CGI and 
SSI-based error pages is implicit.

The fix also extends the SSI command set with basic support for the SSI 'echo' 
command ( http://www.ssi-developer.net/ssi/ssi-echo.shtml ) so that the 
included sample error pages ( /error/error.shtml and /error/404.html ) can 
print the HTTP response code and accompanying error message text.

Using $E in the error_file URLs is replaced by the error status code, e.g.
  -error_file=404=/error/fnf.html;0=/error/$E.shtml
would try to serve '/error/fnf.html' for a 404 error, and '/error/501.shtml' 
for a 501 error.

Original comment by ger.hobbelt on 14 Jun 2012 at 12:04

GoogleCodeExporter commented 8 years ago
Pushed 
https://github.com/cesanta/mongoose/commit/5fb275e14651c819b4b2805e4d68680e23114
a20
This utilizes -url_rewrites option: if rewritten URI is a number, it is treated 
as error page.
Example: to redirect all 404 errors to error.cgi, do:

mongoose -url_rewrites 404=/error.cgi

Then, error.cgi will be called with two parameters: error code and original URI:
http://my_server.com/error.cgi?code=404&orig_uri=/dsd

Original comment by valenok on 9 Jan 2014 at 12:41