NAME

AnyEvent::HTTPD::Request - A web application request handle for AnyEvent::HTTPD

DESCRIPTION

This is the request object as generated by AnyEvent::HTTPD and given in the request callbacks.

METHODS

url

This method returns the URL of the current request.

respond ([$res])

This method will send a response to the request. If no $res argument was given eventually accumulated output will be send as text/html.

Otherwise $res can be:

  • an array reference

    Then the array reference has these elements:

    my ($code, $message, $header_hash, $content) =
          [200, 'ok', { 'Content-Type' => 'text/html' }, '<h1>Test</h1>' }]
  • a hash reference

    If it was a hash reference the hash is first searched for the redirect key and if that key does not exist for the content key.

    The value for the redirect key should contain the URL that you want to redirect the request to.

    The value for the content key should contain an array reference with the first value being the content type and the second the content.

Here is an example:

$httpd->reg_cb (
   '/image/elmex' => sub {
      my ($httpd, $req) = @_;

      open IMG, "$ENV{HOME}/media/images/elmex.png"
         or $req->respond (
               [404, 'not found', { 'Content-Type' => 'text/plain' }, 'not found']
            );

      $req->respond ({ content => ['image/png', do { local $/; <IMG> }] });
   }
);
responded

Returns true if this request already has been responded to.

parm ($key)

Returns the first value of the form parameter $key or undef.

params

Returns list of parameter names.

vars

Returns a hash of form parameters. The value is either the value of the parameter, and in case there are multiple values present it will contain an array reference of values.

method

This method returns the method of the current request.

content

Returns the request content or undef if only parameters for a form were transmitted.

COPYRIGHT & LICENSE

Copyright 2008 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.