CGI: apache canned response

CGI: apache canned response

Post by D » Mon, 15 Oct 2001 12:33:02



in mod_cgi.c
cgi_handler()
{
...
return OK;      /* NOT r->status, even if it has changed. */

Quote:}

So how can my CGI script cause a canned response?
 
 
 

CGI: apache canned response

Post by Joe Schaefe » Mon, 15 Oct 2001 15:11:35



> in mod_cgi.c
> cgi_handler()
> {
> ...
> return OK; /* NOT r->status, even if it has changed. */
> }

> So how can my CGI script cause a canned response?

It's not clear to me what you mean by "canned response", but
CGI v1.1 permits a "Status: " header from the script to be
parsed into a proper HTTP response line.  Apache's mod_cgi
supports this via the ap_scan_script_header_err_core() function
in src/main/util_script.c.

Perhaps you are confusing the request status (r->status) with
the mod_cgi handler's return value?

--
Joe Schaefer

 
 
 

CGI: apache canned response

Post by D » Tue, 16 Oct 2001 01:34:44




> > in mod_cgi.c
> > cgi_handler()
> > {
> > ...
> > return OK;    /* NOT r->status, even if it has changed. */
> > }

> > So how can my CGI script cause a canned response?

> It's not clear to me what you mean by "canned response", but
> CGI v1.1 permits a "Status: " header from the script to be
> parsed into a proper HTTP response line.  Apache's mod_cgi
> supports this via the ap_scan_script_header_err_core() function
> in src/main/util_script.c.

> Perhaps you are confusing the request status (r->status) with
> the mod_cgi handler's return value?

"canned response" == ap_send_error_response()

What I mean is that for example if I generate a "Status: 400 Bad
Request" header then I have to generate the HTML that goes with this.
mod_cgi sets r->status to 400 but returns OK.  Maybe I am wrong, but I
believe that if the handler returned 400 that apache would generate
the HTML for me.  I was just wondering if this was possilbe.

I just implemented my workaround.  I put out a couple of Error*.html
documents and am using the "location: " header to redirect to them.  I
suppose I should have the CGI spit them out instead.

 
 
 

CGI: apache canned response

Post by Marc Slem » Tue, 16 Oct 2001 06:16:42



>"canned response" == ap_send_error_response()

>What I mean is that for example if I generate a "Status: 400 Bad
>Request" header then I have to generate the HTML that goes with this.
>mod_cgi sets r->status to 400 but returns OK.  Maybe I am wrong, but I
>believe that if the handler returned 400 that apache would generate
>the HTML for me.  I was just wondering if this was possilbe.

Apache doesn't support that.

The problem with doing it that way by default is that it would violate
the CGI spec and make it impossible for a CGI to return its own response
body, since Apache would override it.  Well, actually, Apache would
probably get very confused and do broken things since the response
has already been sent by the time the CGI handler returns, so it can't
send it's internal one.

Sure, you could have an option that would do that or that would do it
iff there was no response body returned by the CGI, but that isn't
currently there and you may have some difficulties implementing it for
various reasons.

Quote:>I just implemented my workaround.  I put out a couple of Error*.html
>documents and am using the "location: " header to redirect to them.  I
>suppose I should have the CGI spit them out instead.

Well, if you just do "Location: foo" instead of "Location http://server/foo"
then Apache will do an internal redirect, and the client will never know
the response isn't directly from the CGI, so that's just fine.
 
 
 

CGI: apache canned response

Post by Jeffrey Goldber » Tue, 16 Oct 2001 06:21:50




Quote:> in mod_cgi.c
> cgi_handler()
> {
> ...
> return OK; /* NOT r->status, even if it has changed. */
> }

> So how can my CGI script cause a canned response?

Read the comment.  That "OK" doesn't go into an HTTP header.  All it does
is tell the apache core that this handler has dealt with the request.
Dealing with that request may well involve some "canned response".

Or have I misunderstood your question.

-j

--
Jeffrey Goldberg
 I have recently moved, see http://www.goldmark.org/jeff/contact.html
 Relativism is the triumph of authority over truth, convention over justice
 From line IS valid, but use reply-to.

 
 
 

1. Forcing a 404 (Not Found) response within CGI script (Apache)

I have a namespace on my server that is handles by a script vis (Apache):

ScriptAlias /foo /home/apache/cgi/fooscript

Whilst /foo/bar and /foo/bif are both valid URLs on my server, /foo/gone
isnt, and I would like my script to be able to generate a proper 404,
mainly for the benefit of spiders.  Whilst I know I could do a
semi-satisfactory 302 via:

Redirect gone /foo/gone

before the ScriptAlias directive, the namespace is really to dynamic to be
controlled through httpd.conf, which in any case would require a server
restart at regular intervals. Also, there are clearly an infinite number of
invalid urls.

I also thought about forcing a 500 Server Error, but again, it's far from ideal.

Thoughts appreciated.

Nick

--
Nick Perry   | Home / Recreation          | Work - AboarD Boats & Yachts
____________ | LONDON SW1, UK             | LONDON SW10 0TB     UK
Internet,    | http://www.amulation.co.uk | http://www.aboard.co.uk

Theatre,     -----------------------------------------------------------
Coffee, Tea, Multimedia, Macs, Photography, Print Publishing, etc, etc..

2. Compiling with gcc, libraries missing? workarounds?y

3. Logging CGI response size (Apache 1.3.9)

4. rs/60000,graphics

5. Slow response from Apache (MAC, CGI)

6. Linux META-FAQ

7. /cgi-bin/phf /cgi-bin/test-cgi /cgi-bin/handler

8. pptp-linux

9. Apache/CGI: How to toggle an ErrorDocument from a CGI ?

10. WAP/WML cgi broken! apache/mod_perl CGI::WML

11. apache: give /home/mailman/cgi-bin permissions to run cgi-scripts.

12. Cannot execute CGI programs in /cgi-bin with Apache

13. Apache, cgi forms, cgi programs - issues - restart resolves issue??