[FASTCGI] FastCGI-developers Digest, Vol 15, Issue 10
Rob Lemley
rclemley at booksys.com
Thu Oct 29 18:41:16 EDT 2009
Great! I guess that's one of the differences between
AliasMatch ^/(path/to/yourfiles/*.ext) /yourfastcgiserver
and
AddHandler my-file-type .xyz
Action my-file-type /myfastcgiapp
In my AliasMatched fastcgi server, I don't even get a PATH_TRANSLATED var.
tbandrowsky wrote:
> Hey, some answers! I managed to get it to work and I'm super excited
> about it. For the purposes of having a FastCGI process multiple
> different files, the following worked, for Apache (This was on an Ubuntu
> based machine). In the below, xspserve is the name of my C++ FastCGI.
>
> FastCGIServer /var/www/xsp-bin/xspserve
> AddType application/x-httpd-fastxsp xsp
> Action application/x-httpd-fastxsp /xsp-bin/xspserve
>
> <Directory "/var/www/xsp-bin">
> AllowOverride None
> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
> </Directory>
>
> To read the file that is my "custom script" file, I found that
> PATH_TRANSLATED seemed to be the one that did what I needed.
> SCRIPT_NAME game the name of the C++ chumpy itself, and that simply
> wasn't what I was looking for.
>
> Todd
>
> On Wed, 2009-10-28 at 12:00 -0400,
> fastcgi-developers-request at mailman.fastcgi.com wrote:
>
>> Send FastCGI-developers mailing list submissions to
>> fastcgi-developers at mailman.fastcgi.com
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> http://mailman.pins.net/mailman/listinfo.cgi/fastcgi-developers
>> or, via email, send a message with subject or body 'help' to
>> fastcgi-developers-request at mailman.fastcgi.com
>>
>> You can reach the person managing the list at
>> fastcgi-developers-owner at mailman.fastcgi.com
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of FastCGI-developers digest..."
>>
>>
>> Today's Topics:
>>
>> 1. Re: FastCGI as a Filter? (Rob Lemley)
>> 2. Re: FastCGI as a Filter? (tbandrowsky)
>> 3. Is there any method (within fcgi) to return a different HTTP
>> status code than '200 OK'? (Rick Thorne)
>>
>>
>> ----------------------------------------------------------------------
>>
>>
>> Message: 1
>> Date: Tue, 27 Oct 2009 14:01:32 -0500
>> From: Rob Lemley <rclemley at booksys.com>
>> Subject: Re: [FASTCGI] FastCGI as a Filter?
>> To: fastcgi-developers at mailman.pins.net
>> Message-ID: <4AE7438C.7070901 at booksys.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> Date: Sat, 24 Oct 2009 23:52:55 -0400
>>
>>> From: tbandrowsky <tbandrowsky at treatyist.com>
>>> Subject: [FASTCGI] FastCGI as a Filter?
>>>
>>> I'm trying to make heads or tales of whether or not Apache 2 supports
>>> FastCGI as a filter. Basically, I want to have a bunch of files with a
>>> particular extension in a directory all get passed through to my FastCGI
>>> application rather than get spewed out directly. I've read that one
>>> does not need filters to do this, although clearly, filters look like
>>> they would be a pretty elegant approach. Can I do this sort of a thing
>>> with Apache, or am I just banged and should use something like Sun's web
>>> server?
>>>
>>>
>> Apparently mod_fastcgi (the apache fastcgi module) does not support
>> FastCGI filter role:
>>
>> "mod_fastcgi does not implement the Authorizer or Filter roles described
>> in the FastCGI specification. However, you can approximate the Filter
>> role using Apache's Action directive to route requests to a FastCGI
>> Responder. See the documentation for mod_actions for information on the
>> Action directive."
>> (http://www.fastcgi.com/om_archive/servers/apache/apache-fastcgi/mod_fastcgi.html)
>>
>> The mod_action solution (which I have no experience with) seems to catch
>> all files with a given mime-type or, in this case, extension:
>> # Files of a particular file extension
>> AddHandler my-file-type .xyz
>> Action my-file-type /cgi-bin/program.cgi
>>
>> which, translated to FastCGI, I think would look something like (untested):
>>
>> # Files of a particular file extension
>> AddHandler my-file-type .xyz
>> Action my-file-type /myfastcgiapp
>> FastCgiServer /myfastcgiapp ....
>>
>> I believe the way to set this up with apache AliasMatch directive,
>> which allows you to capture input requests based on a more general
>> regular expression pattern, to set the Apache2 "AliasMatch" directive to
>> pass only the files you want to filter to your FastCGI server:
>>
>> #APACHE CONFIG:
>>
>> # NameVirtualHost *:80
>>
>> <VirtualHost *:80>
>> ServerName yourserver.example.com
>> ServerAlias yourserver
>> AliasMatch ^/(path/to/yourfiles/*.ext) /yourfastcgiserver
>> </VirtualHost>
>>
>> FastCgiExternalServer /yourfastcgiserver -socket
>> /var/run/yourfastcgiserver/socket
>>
>> #END OF APACHE CONFIG
>>
>> Next, you would implement the FastCGI server to read the files and
>> filter them as necessary. This usage of FastCGI is fairly well known
>> and I don't have a good concise example in my own code. To filter these
>> files, generally all you would do is open the filename found in the
>> FastCGI Environment (CGI) variable "SCRIPT_NAME." You might need to
>> adjust the directory or something depending on how your server namespace
>> is set up.
>>
>> while accept_fastcgi_request(request)
>> #FCGX_Accept(), etc
>> script_name = lookup(request.envp, "SCRIPT_NAME")
>> filter(script_name) # writes
>> using FCGX_PutStr(), may need to Put the HTTP response header too.
>> endwhile
>>
>>
>> All of the information about the request will come through the FastCGI
>> request. You'll look at various fields in the FastCGI environment to
>> determine the file to open and filter. Generally your program might
>> look at REQUEST_URI, QUERY_STRING and SCRIPT_NAME. You may also want to
>> check for POST request data in some case (depends on having
>> "CONTENT_TYPE=multipart/form-data; boundary.....). Or you can just
>> ignore any query string and post data and just filter the SCRIPT_NAME.
>>
>> NOTE: usually (always?) REQUEST_URI == SCRIPT_NAME + "?" + QUERY_STRING
>>
>> Rob
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <http://mailman.pins.net/mailman/private.cgi/fastcgi-developers/attachments/20091027/51de45cd/attachment-0001.html>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Tue, 27 Oct 2009 22:30:47 -0400
>> From: tbandrowsky <tbandrowsky at treatyist.com>
>> Subject: Re: [FASTCGI] FastCGI as a Filter?
>> To: Garrett Wollman <wollman at csail.mit.edu>
>> Cc: fastcgi-developers at mailman.pins.net
>> Message-ID: <1256697047.3271.5.camel at tbandrow-desktop>
>> Content-Type: text/plain; charset="UTF-8"
>>
>> Thanks! Turns out that is exactly what I was trying to do and it works
>> wonderfully.
>>
>> On Mon, 2009-10-26 at 11:53 -0400, Garrett Wollman wrote:
>>
>>> <<On Sat, 24 Oct 2009 23:52:55 -0400, tbandrowsky <tbandrowsky at treatyist.com> said:
>>>
>>>
>>>> I'm trying to make heads or tales of whether or not Apache 2 supports
>>>> FastCGI as a filter. Basically, I want to have a bunch of files with a
>>>> particular extension in a directory all get passed through to my FastCGI
>>>> application rather than get spewed out directly.
>>>>
>>> That's pretty easy to accomplish, although I don't know about using
>>> the filter mechanism for that. Here's what we do for PHP:
>>>
>>> ScriptAlias /.php5-cgi /usr/bin/php5-cgi
>>> Action php5-script /.php5-cgi
>>> Action application/x-httpd-fastphp5 /.php5-cgi
>>>
>>> AddType application/x-httpd-fastphp5 php5
>>>
>>> -GAWollman
>>>
>>>
>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Wed, 28 Oct 2009 10:51:09 -0400
>> From: Rick Thorne <Rick at LandbaseSystems.com>
>> Subject: [FASTCGI] Is there any method (within fcgi) to return a
>> different HTTP status code than '200 OK'?
>> To: fastcgi-developers at mailman.fastcgi.com
>> Message-ID:
>> <20091028145114.4F00F7C08D at smtp-ext-01.mx.pitdc1.expedient.net>
>> Content-Type: text/plain; charset="us-ascii"; format=flowed
>>
>> 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)
>>
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> FastCGI-developers mailing list
>> FastCGI-developers at mailman.fastcgi.com
>> http://mailman.pins.net/mailman/listinfo.cgi/fastcgi-developers
>>
>>
>> End of FastCGI-developers Digest, Vol 15, Issue 10
>> **************************************************
>>
>>
>
>
> _______________________________________________
> FastCGI-developers mailing list
> FastCGI-developers at mailman.fastcgi.com
> http://mailman.pins.net/mailman/listinfo.cgi/fastcgi-developers
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.pins.net/mailman/private.cgi/fastcgi-developers/attachments/20091029/2b342a33/attachment.html>
More information about the FastCGI-developers
mailing list