SYNOPSIS
use AnyEvent;
use AnyEvent::FCGI;
use CGI::Stateless;
my $fcgi = new AnyEvent::FCGI(
port => 9000,
on_request => sub {
my $request = shift;
local *STDIN; open STDIN, '<', \$request->read_stdin;
local %ENV = %{$request->params};
local $CGI::Q = new CGI::Stateless;
$request->respond(
'Hello, ' . (CGI::param('name') || 'anonymous'),
'Content-Type' => 'text/html; charset=utf8',
'Set-Cookie' => 'cookie_a=1; path=/',
'Set-Cookie' => 'cookie_b=2; path=/',
);
}
);
AnyEvent->loop;
DESCRIPTION
This is the request object as generated by AnyEvent::FCGI. When given to the controlling program, each request will already have its parameters and STDIN data. The program can then write response data to the STDOUT stream, messages to the STDERR stream, and eventually finish it.This module would not be used directly by a program using "AnyEvent::FCGI", but rather, objects in this class are passed into the "on_request" callback of the containing "AnyEvent::FCGI" object.
METHODS
is_active
Returns false if the webserver has already closed the control connection. No further work on this request is necessary, as it will be discarded.This method can be used if response will not be sent immediately from "on_request" callback.
param($key)
This method returns the value of a single request parameter, or "undef" if no such key exists.params
This method returns a reference to a hash containing a copy of the request parameters that had been sent by the webserver as part of the request.read_stdin($size)
This method works similarly to the "read(HANDLE)" function. It returns the next block of up to $size bytes from the STDIN buffer. If no data is available any more, then "undef" is returned instead.print_stdout($data)
This method appends the given data to the STDOUT stream of the FastCGI request, sending it to the webserver to be sent to the client.print_stderr($data)
This method appends the given data to the STDERR stream of the FastCGI request, sending it to the webserver.finish
When the request has been dealt with, this method should be called to indicate to the webserver that it is finished. After calling this method, no more data may be appended to the STDOUT stream.respond($content, @headers)
This method sends the response to the webserver and finishes the request. HTTP reply code can be specified in "Status" header (200 by default). This method can be used instead of "print_stdout" and "finish".