man Apache2::RequestIO () - Perl API for Apache request record IO

NAME

Apache2::RequestIO - Perl API for Apache request record IO

Synopsis

  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);

Description

CWApache2::RequestIO provides the API to perform IO on the Apache request object.

API

CWApache2::RequestIO provides the following functions and/or methods: In 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();
The current request CWAPR::Const status constant if request is malformed, CWApache2::Const::OK otherwise.
since: 2.0.00

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;
Send data to the client.

  $cnt = $r->print(@msg);
Data to send How many bytes were sent (or buffered). If zero bytes were sent, CWprint will return CW0E0, or zero but true, which will still evaluate to CW0 in a numerical context.
since: 2.0.00

The data is flushed only if STDOUT stream's CW$| is true. Otherwise it's buffered up to the size of the buffer, flushing only excessive data. Format and send data to the client (same as CWprintf).

  $cnt = $r->printf($format, @args);
Format string, as in the Perl core CWprintf function. Arguments to be formatted, as in the Perl core CWprintf function. How many bytes were sent (or buffered)
since: 2.0.00

The data is flushed only if STDOUT stream's CW$| is true. Otherwise it's buffered up to the size of the buffer, flushing only excessive data. Send data to the client

  $cnt = $r->puts(@msg);
Data to send How many bytes were sent (or buffered)
since: 2.0.00

CWputs() is similar to CWCIprint()CW, but it won't attempt to flush data, no matter what the value of STDOUT stream's CW$| is. Therefore assuming that STDOUT stream's CW$| is true, this method should be a tiny bit faster than CWCIprint()CW, especially if small strings are printed. Read data from the client.

  $cnt = $r->read($buffer, $len);
  $cnt = $r->read($buffer, $len, $offset);
The buffer to populate with the read data How many bytes to attempt to read If a non-zero CW$offset is specified, the read data will be placed at that offset in the CW$buffer. META: negative offset and \0 padding are not supported at the moment How many characters were actually read
since: 2.0.00

This method shares a lot of similarities with the Perl core CWread() function. The main difference in the error handling, which is done via CWAPR::Error exceptions Flush any buffered data to the client.

  $r->rflush();
ret: no return value
since: 2.0.00

Unless STDOUT stream's CW$| is false, data sent via CW$r->CIprint()CW is buffered. This method flushes that data to the client. Send a file or a part of it

  $rc = $r->sendfile($filename);
  $rc = $r->sendfile($filename, $offset);
  $rc = $r->sendfile($filename, $offset, $len);
The full path to the file (using CW/ on all systems) Offset into the file to start sending. No offset is used if CW$offset is not specified. How many bytes to send. If not specified the whole file is sent (or a part of it, if CW$offset if specified) On success, CWAPR::Const::SUCCESS is returned. In case of a failure a failure code is returned, in which case normally it should be returned to the caller. Exceptions are thrown only when this function is called in the VOID context. So if you don't want to handle the errors, just don't ask for a return value and the function will handle all the errors on its own.
since: 2.0.00
Send partial string to the client

  $cnt = $r->write($buffer);
  $cnt = $r->write($buffer, $len);
  $cnt = $r->write($buffer, $len, $offset);
The string with data How many bytes to send. If not specified, or -1 is specified, all the data in CW$buffer (or starting from CW$offset) will be sent. Offset into the CW$buffer string. How many bytes were sent (or buffered)
since: 2.0.00

Examples:

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

TIE Interface

The TIE interface implementation. This interface is used for HTTP request handlers, when running under CWSetHandler perl-script and Perl doesn't have perlio enabled.

See the perltie manpage for more information.

since: 2.0.00

NoOP

See the binmode Perl entry in the perlfunc manpage

since: 2.0.00

NoOP

See the close Perl entry in the perlfunc manpage

since: 2.0.00

See the fileno Perl entry in the perlfunc manpage

since: 2.0.00

See the getc Perl entry in the perlfunc manpage

since: 2.0.00

See the open Perl entry in the perlfunc manpage

since: 2.0.00

See the print Perl entry in the perlfunc manpage

since: 2.0.00

See the printf Perl entry in the perlfunc manpage

since: 2.0.00

See the read Perl entry in the perlfunc manpage

since: 2.0.00

See the tie Perl entry in the perlfunc manpage

since: 2.0.00

NoOP

See the untie Perl entry in the perlfunc manpage

since: 2.0.00

See the write Perl entry in the perlfunc manpage

Deprecated API

The following methods are deprecated, Apache plans to remove those in the future, therefore avoid using them. This method is deprecated since the C implementation is buggy and we don't want you to use it at all. Instead use the plain CW$r->CIread()CW. This method is deprecated since CW$r->get_client_block is deprecated. This method is deprecated since CW$r->get_client_block is deprecated.

See Also

mod_perl 2.0 documentation.

Copyright

mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.

Authors

The mod_perl development team and numerous contributors.