[FASTCGI] Is there any method (within fcgi) to return a different HTTP status code than '200 OK'?

Rick Thorne Rick at LandbaseSystems.com
Wed Oct 28 10:51:09 EDT 2009


Is there any method (within fcgi) to return a HTTP status code other 
than '200 OK'?

I'm serving up images stored in a database; using fcgi and Apache.

Using www.httpviewer.net to track the response 'back' from our 
server, a request for an existing image (through our fcgi 
application) returns the following HTTP information:
   HTTP/1.1 200 OK(CR)(LF)
   Date: Tue, 27 Oct 2009 16:57:57 GMT(CR)(LF)
   Server: Apache/2.2.11 (Win32) PHP/5.3.0 mod_fastcgi/2.4.6(CR)(LF)
   Content-Length: 3302(CR)(LF)          <--- written by our fcgi application
   Content-Type: image/png(CR)(LF)               <--- written by our 
fcgi application
   (CR)(LF)                                      <--- written by our 
fcgi application
   ...3302 bytes of .png data                    <--- written by our 
fcgi application

The web page receives and displays the image correctly.

The web page can also generate requests for images that do not exist, 
and these requests also come through our fcgi application (we don't 
know that they do not exist until we attempt to find them in the database).

We'd like to return the '404 Not Found' header for these non-existent 
images, as in:
   HTTP/1.1 404 Not Found(CR)(LF)
   Date: Tue, 27 Oct 2009 17:04:47 GMT(CR)(LF)
   Server: Apache/2.2.11 (Win32) PHP/5.3.0 mod_fastcgi/2.4.6(CR)(LF)
   (CR)(LF)

However, within our fcgi application I don't appear to have control 
over the first three HTTP response lines (the lines that starts with 
'HTTP/1.1', 'Date:', and 'Server:').  I believe Apache generates 
these lines when it successfully parses the fcgi request and finds 
the required fcgi startup file.  Then it calls the fcgi application 
and pushes the data through the pipes to and from our fcgi application.

In other words, apparently all fcgi applications have to work with 
only the 'HTTP/1.1 200 OK(CR)(LF)' response and cannot change this 
response code to another value.

The FCGX_SetExitStatus() command does 'not' control this HTTP 
response code (?I tried w/o success on the output stream, perhaps I 
should have tried the error stream?).

The current workaround I have for this particular issue is to keep 
the '200 OK' response and return an empty .png image.  This solution 
'works' (in this particular example), but I'd also like to be able to 
respond with other HTTP codes for some other error conditions.

Note: I'm writing this fcgi application in 'C', so I can pretty much 
call any (public) operating system/Apache/fcgi dynamic link library 
entry point.

Thoughts and/or suggestions welcome...

Rick Thorne
Landbase Systems Corporation
One World / One Map
(412)563-9120 (Office)
(412)563-9122 (Desk)



More information about the FastCGI-developers mailing list