Web::Request - common request class for web frameworks
version 0.10
use Web::Request; my $app = sub { my ($env) = @_; my $req = Web::Request->new_from_env($env); # ... };
Web::Request is a request class for PSGI applications. It provides access to all of the information received in a request, generated from the PSGI environment. The available methods are listed below.
Note that Web::Request objects are intended to be (almost) entirely read-only - although some methods (headers, uri, etc) may return mutable objects, changing those objects will have no effect on the actual environment, or the return values of any of the other methods. Doing this is entirely unsupported. In addition, the return values of most methods that aren't direct accesses to env are cached, so if you do modify the actual environment hashref, you should create a new Web::Request object for it.
headers
uri
env
The one exception is the encoding attribute, which is allowed to be modified. Changing the encoding will change the return value of any subsequent calls to content, query_parameters, all_query_parameters, body_parameters, and all_body_parameters.
encoding
content
query_parameters
all_query_parameters
body_parameters
all_body_parameters
Web::Request is based heavily on Plack::Request, but with the intention of growing to become more generally useful to end users (rather than just framework and middleware developers). In the future, it is expected to grow in functionality to support a lot more convenient functionality, while Plack::Request has a more minimalist goal.
Returns the IP address of the remote client.
Returns the hostname of the remote client. May be empty.
Returns the protocol (HTTP/1.0, HTTP/1.1, etc.) used in the current request.
Returns the HTTP method (GET, POST, etc.) used in the current request.
Returns the local port that this request was made on.
Returns the contents of the HTTP Host header. If it doesn't exist, falls back to recreating the host from the SERVER_NAME and SERVER_PORT variables.
Host
SERVER_NAME
SERVER_PORT
Returns the request path for the current request. Unlike path_info, this will never be empty, it will always start with /. This is most likely what you want to use to dispatch on.
path_info
/
Returns the request path for the current request. This can be '' if script_name ends in a /. This can be appended to script_name to get the full (absolute) path that was requested from the server.
''
script_name
Returns the absolute path where your application is mounted. It may be '' (in which case, path_info will start with a /).
Returns the raw, undecoded URI path (the literal path provided in the request, so /foo%20bar in GET /foo%20bar HTTP/1.1). You most likely want to use path, path_info, or script_name instead.
/foo%20bar
GET /foo%20bar HTTP/1.1
path
Returns http or https depending on the scheme used in the request.
http
https
Returns the session object, if a middleware is used which provides one. See PSGI::Extensions.
Returns the session options hashref, if a middleware is used which provides one. See PSGI::Extensions.
Returns the logger object, if a middleware is used which provides one. See PSGI::Extensions.
Returns the full URI used in the current request, as a URI object.
Returns the base URI for the current request (only the components up through script_name) as a URI object.
Returns a HTTP::Headers object containing the headers for the current request.
The length of the content, in bytes. Corresponds to the Content-Length header.
Content-Length
The MIME type of the content. Corresponds to the Content-Type header.
Content-Type
The encoding of the content. Corresponds to the Content-Encoding header.
Content-Encoding
Returns the value of the Referer header.
Referer
Returns the value of the User-Agent header.
User-Agent
Shortcut for $req->headers->header($name).
$req->headers->header($name)
Returns a hashref of cookies received in this request. The values are URI decoded.
Returns the content received in this request, decoded based on the value of encoding.
Returns the parameter value for the parameter named $param. Returns the last parameter given if more than one are passed.
$param
Returns a hashref of parameter names to values. If a name is given more than once, the last value is provided.
Returns a hashref where the keys are parameter names and the values are arrayrefs holding every value given for that parameter name. All parameters are stored in an arrayref, even if there is only a single value.
Like parameters, but only return the parameters that were given in the query string.
parameters
Like all_parameters, but only return the parameters that were given in the query string.
all_parameters
Like parameters, but only return the parameters that were given in the request body.
Like all_parameters, but only return the parameters that were given in the request body.
Returns a hashref of upload objects (instances of upload_class). If more than one upload is provided with a given name, returns the last one given.
upload_class
Returns a hashref where the keys are upload names and the values are arrayrefs holding an upload object (instance of upload_class) for every upload given for that name. All uploads are stored in an arrayref, even if there is only a single value.
Returns a new response object, passing @params to its constructor.
@params
Returns the PSGI environment that was provided in the constructor (or generated from the HTTP::Request, if new_from_request was used).
new_from_request
Returns the encoding that was provided in the constructor. You can also pass an encoding name to this method to set the encoding that will be used to decode the content and encode the response. For instance, you can set the encoding to UTF-8 in order to read the body content and parameters, and then set the encoding to undef at the end of the handler in order to indicate that the response should not be encoded (for instance, if it is a binary file).
undef
Returns the name of the class to use when creating a new response object via new_response. Defaults to Web::Response. This can be overridden in a subclass.
new_response
Returns the name of the class to use when creating a new upload object for uploads or all_uploads. Defaults to Web::Request::Upload. This can be overridden in a subclass.
uploads
all_uploads
Returns the name of the default encoding to use for decoding. Defaults to iso8859-1. This can be overridden in a subclass.
Create a new Web::Request object from a PSGI environment hashref.
Create a new Web::Request object from a HTTP::Request object.
Create a new Web::Request object with named parameters. Valid parameters are:
A PSGI environment hashref. Required.
The encoding to use for decoding all input in the request and encoding all output in the response. Defaults to the value of default_encoding. If undef is passed, no encoding or decoding will be done.
default_encoding
No known bugs.
Please report any bugs through RT: email bug-web-request at rt.cpan.org, or browse to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Web-Request.
bug-web-request at rt.cpan.org
Plack::Request - Much of this module's API and implementation were taken from Plack::Request.
You can find this documentation for this module with the perldoc command.
perldoc Web::Request
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Web-Request
CPAN Ratings
http://cpanratings.perl.org/d/Web-Request
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Web-Request
Search CPAN
http://search.cpan.org/dist/Web-Request
Jesse Luehrs <doy at cpan dot org>
This software is copyright (c) 2013 by Jesse Luehrs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Web::Request, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Request
CPAN shell
perl -MCPAN -e shell install Web::Request
For more information on module installation, please visit the detailed CPAN module installation guide.