NAME

PEF::Front::Request - HTTP request object from PSGI env hash

SYNOPSIS

package My::Local::Test;

sub test {
  my ($msg, $context) = @_;
  return {
      result    => "OK",
      data      => [1, 2],
      path_info => $context->{request}->path_info
  };
}

DESCRIPTION

PEF::Front::Request provides a consistent API for request objects across PEF::Front framework.

CAVEAT

This module is intended to be used by web application developers only in rare circumstances. Developers can receive an object of this type in "Local", "InFilter" and "OutFilter" handlers via hash "context".

METHODS

Unless otherwise noted, all methods and attributes are read-only, and passing values to the method like an accessor doesn't work like you expect it to.

new($env)
PEF::Front::Request->new( $env );

Creates a new request object from supplied $env hash.

env()

Returns the shared PSGI environment hash reference. This is a reference, so writing to this environment passes through during the whole PSGI request/response cycle.

remote_ip()

Returns the IP address of the client (REMOTE_ADDR).

http_method()

Contains the request method (GET, POST, HEAD, etc) from HTTP protocol directly.

method()

Contains the request method (GET, POST, HEAD, etc) from HTTP protocol but it understands also X-HTTP-Method-Override header and WEBSOCKET, SSE types of request.

protocol()

Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.

request_uri()

Returns the raw, undecoded request URI path. You probably do NOT want to use this to dispatch requests.

path_info()

Returns PATH_INFO in the environment. Use this to get the local path for the requests.

path ( [$path] )

Similar to path_info but can be changed during internal routing process. Decoded to utf8 perl internal representation.

query_string()

Returns QUERY_STRING in the environment. This is the undecoded query string in the request URI.

script_name()

Returns SCRIPT_NAME in the environment. This is the absolute path where your application is hosted. NOT TESTED

scheme()

Returns the scheme (http or https) of the request.

secure()

Returns true or false, indicating whether the connection is secure (https).

uri()

Returns an URI object for the current request.

Every time this method is called it returns a new, cloned URI object.

logger()

Returns (optional) configured cfg_logger or psgix.logger code reference. When it exists, your application is supposed to send the log message to this logger, using:

$req->logger->({ level => 'debug', message => "This is a debug message" });
cookies()

Returns a reference to a hash containing the cookies. Values are strings that are sent by clients and are URI decoded.

If there are multiple cookies with the same name in the request, this method will ignore the duplicates and return only the first value. If that causes issues for you, you may have to use modules like CGI::Simple::Cookie to parse <$request-header('Cookies')>> by yourself.

params()

Returns a hash reference containing (merged) GET and POST parameters.

raw_body()

Returns the request content in an undecoded byte string for POST requests.

hostname()

Returns hostname of current request.

base()

Returns full URL string of current request.

user()

Returns REMOTE_USER if it's set.

headers()

Returns an PEF::Front::HTTPHeaders object containing the headers for the current request.

content_encoding()

Shortcut to $req->headers->get_header("content_encoding").

content_length()

Returns length of content.

content_type()

Returns Content-Type header value.

header()

Shortcut to $req->headers->get_header.

referer()

Shortcut to $req->headers->get_header("referer").

user_agent()

Shortcut to $req->headers->get_header("user_agent").

param($param, [$value])

Returns GET and POST parameters. This is an alternative method for accessing parameters in $req->params. It does allow setting or modifying query parameters.

get_out_header($header)
get_out_cookie($cookie)
set_out_header($header, $value)
set_out_cookie($cookie, $value)
remove_out_header($header)
remove_out_cookie($cookie)

Set/get/remove headers and cookies that will be copied into response object.

note($key, $value)

Set/get some extra info for request. Usefule during routing phase when context is not made up yet.

AUTHORS

Anton Petrusevich.

Copyright and License

Copyright (c) 2014 - 2016 Anton Petrusevich. Some Rights Reserved.

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