David Kaufman wrote:
Hi Barry, Barry Hoggard <suppressed> wrote:Is there a good way to return a 404 error from the AUTOLOAD run mode, or inside a normal run mode (such as when a bad parameter value comes in)? I know I can return a not found page programmatically that has a 200 status, but I want a real 404 error for some applications.I use something like this: sub not_found { my $self = shift; $self->header_props(-status => '404 (pretending to be) Not Found'); return ''; } so I can return $self->not_found() from other run-modes conveniently.To the browser, its pretty much indistinguishable from a "real" apache 404. The "(pretending to be)" string only shows up in the HTTP status headers and of course you can make it more authentic-looking by leaving that bit out.
I definitely see a different result. I get just a blank page with this test: #!/usr/bin/perl use CGI; my $q = new CGI; print $q->header( -status => '404 Not Found' ); ####In my experience it is "too late" to return a true 404 response in CGI, but is possible in mod_perl, I think.
We deal with this issue in CGI::Application::Dispatch. Basically, it seems like the choices in CGI are:
1. Redirect to the 404 page. This is still not a true 404 response,but just a 302 redirect to the error page, which returns a 200 response as it is served. Also, the URL visibly changes in the location bar
2. Serve the 404 page as a run mode, and return a 404 status code. CGI::Application::Dispatch doesn't currently do this, but it's my latest thinking about the Best Way.
Mark
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.