| Apache2::RequestIO - Perl API for Apache request record IO |
Apache2::RequestIO - Perl API for Apache request record IO
use Apache2::RequestIO ();
$rc = $r->discard_request_body();
$r->print("foo", "bar");
$r->puts("foo", "bar"); # same as print, but no flushing
$r->printf("%s $d", "foo", 5);
$r->read($buffer, $len);
$r->rflush();
$r->sendfile($filename);
$r->write("foobartarcar", 3, 5);
Apache2::RequestIO provides the API to perform IO on the Apache request object.
Apache2::RequestIO provides the following functions and/or methods:
discard_request_bodyIn HTTP/1.1, any method can have a body. However, most GET handlers wouldn't know what to do with a request body if they received one. This helper routine tests for and reads any message body in the request, simply discarding whatever it receives. We need to do this because failing to read the request body would cause it to be interpreted as the next request on a persistent connection.
$rc = $r->discard_request_body();
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )$rc ( integer )APR::Const status constant|docs::2.0::api::APR::Const if request
is malformed, Apache2::Const::OK otherwise.
Since we return an error status if the request is malformed, this routine should be called at the beginning of a no-body handler, e.g.,
use Apache2::Const -compile => qw(OK); $rc = $r->discard_request_body; return $rc if $rc != Apache2::Const::OK;
printSend data to the client.
$cnt = $r->print(@msg);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )@msg ( ARRAY )$cnt ( number )print will return 0E0, or ``zero but true,'' which
will still evaluate to 0 in a numerical context.
APR::Error|docs::2.0::api::APR::ErrorThe data is flushed only if STDOUT stream's $| is true. Otherwise
it's buffered up to the size of the buffer, flushing only excessive
data.
printfFormat and send data to the client (same as printf).
$cnt = $r->printf($format, @args);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )$format ( string )printf function.
@args ( ARRAY )printf function.
$cnt ( number )APR::Error|docs::2.0::api::APR::ErrorThe data is flushed only if STDOUT stream's $| is true. Otherwise
it's buffered up to the size of the buffer, flushing only excessive
data.
putsSend data to the client
$cnt = $r->puts(@msg);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )@msg ( ARRAY )$cnt ( number )APR::Error|docs::2.0::api::APR::Errorputs() is similar to print()|/C_print_, but it won't attempt
to flush data, no matter what the value of STDOUT stream's $|
is. Therefore assuming that STDOUT stream's $| is true, this method
should be a tiny bit faster than print()|/C_print_, especially
if small strings are printed.
readRead data from the client.
$cnt = $r->read($buffer, $len); $cnt = $r->read($buffer, $len, $offset);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )$buffer ( SCALAR )$len ( number )$offset ( number )$offset is specified, the read data will be placed at
that offset in the $buffer.
META: negative offset and \0 padding are not supported at the moment
$cnt ( number )APR::Error|docs::2.0::api::APR::ErrorThis method shares a lot of similarities with the Perl core read()
function. The main difference in the error handling, which is done via
APR::Error exceptions|docs::2.0::api::APR::Error
rflushFlush any buffered data to the client.
$r->rflush();
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )Unless STDOUT stream's $| is false, data sent via
$r->print()|/C_print_ is buffered. This method flushes that
data to the client.
sendfileSend a file or a part of it
$rc = $r->sendfile($filename); $rc = $r->sendfile($filename, $offset); $rc = $r->sendfile($filename, $offset, $len);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )$filename ( string )/ on all systems)
$offset ( integer )No offset is used if $offset is not specified.
$len ( integer )If not specified the whole file is sent (or a part of it, if
$offset if specified)
$rc ( APR::Const status
constant|docs::2.0::api::APR::Const> )APR::Const::SUCCESS|docs::2.0::api::APR::Const/C_APR__SUCCESS_ is
returned.
In case of a failure -- a failure code is returned, in which case normally it should be returned to the caller.
APR::Error|docs::2.0::api::APR::Error
writeSend partial string to the client
$cnt = $r->write($buffer); $cnt = $r->write($buffer, $len); $cnt = $r->write($buffer, $len, $offset);
$r
( Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec )$buffer ( SCALAR )$len ( SCALAR )$buffer (or starting from $offset) will be sent.
$offset ( number )$buffer string.
$cnt ( number )APR::Error|docs::2.0::api::APR::ErrorExamples:
Assuming that we have a string:
$string = "123456789";
Then:
$r->write($string);
sends:
123456789
Whereas:
$r->write($string, 3);
sends:
123
And:
$r->write($string, 3, 5);
sends:
678
Finally:
$r->write($string, -1, 5);
sends:
6789
The TIE interface implementation. This interface is used for HTTP
request handlers, when running under SetHandler
perl-script|docs::2.0::user::config::config/C_perl_script_> and
Perl doesn't have perlio enabled.
See the perltie manpage for more information.
BINMODENoOP
See the binmode Perl entry in the perlfunc manpage
CLOSENoOP
See the close Perl entry in the perlfunc manpage
FILENOSee the fileno Perl entry in the perlfunc manpage
GETCSee the getc Perl entry in the perlfunc manpage
OPENSee the open Perl entry in the perlfunc manpage
PRINTSee the print Perl entry in the perlfunc manpage
PRINTFSee the printf Perl entry in the perlfunc manpage
READSee the read Perl entry in the perlfunc manpage
TIEHANDLESee the tie Perl entry in the perlfunc manpage
UNTIENoOP
See the untie Perl entry in the perlfunc manpage
WRITESee the write Perl entry in the perlfunc manpage
The following methods are deprecated, Apache plans to remove those in the future, therefore avoid using them.
get_client_blockThis method is deprecated since the C implementation is buggy and we
don't want you to use it at all. Instead use the plain
$r->read()|/C_read_.
setup_client_blockThis method is deprecated since
$r->get_client_block|/C__get_client_block_ is deprecated.
should_client_blockThis method is deprecated since
$r->get_client_block|/C__get_client_block_ is deprecated.
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
The mod_perl development team and numerous contributors.
| Apache2::RequestIO - Perl API for Apache request record IO |