- DEFAULT MAPPINGS
- COPYRIGHT AND LICENSE
HTTP::Headers::ActionPack - HTTP Action, Adventure and Excitement
use HTTP::Headers::ActionPack; my $pack = HTTP::Headers::ActionPack->new; my $media_type = $pack->create_header( 'Content-Type' => 'application/xml;charset=UTF-8' ); my $link = $pack->create( 'LinkHeader' => [ '</test/tree>', rel => "up" ] ); # auto-magic header inflation # for multiple types $pack->inflate( $http_headers_instance ); $pack->inflate( $http_request_instance ); $pack->inflate( $plack_request_instance );
This is a module to handle the inflation and deflation of complex HTTP header types. In many cases header values are simple strings, but in some cases they are complex values with a lot of information encoded in them. The goal of this module is to make the parsing and analysis of these headers as easy as calling
inflate on a compatible object (see below for a list).
This top-level class is basically a Factory for creating instances of the other classes in this module. It contains a number of convenience methods to help make common cases easy to write.
This class provides a set of default mappings between HTTP headers and the classes which can inflate them. Here is the list of default mappings this class provides.
Link HTTP::Headers::ActionPack::LinkList Content-Type HTTP::Headers::ActionPack::MediaType Accept HTTP::Headers::ActionPack::MediaTypeList Accept-Charset HTTP::Headers::ActionPack::PriorityList Accept-Encoding HTTP::Headers::ActionPack::PriorityList Accept-Language HTTP::Headers::ActionPack::PriorityList Date HTTP::Headers::ActionPack::DateHeader Client-Date HTTP::Headers::ActionPack::DateHeader Expires HTTP::Headers::ActionPack::DateHeader Last-Modified HTTP::Headers::ActionPack::DateHeader If-Unmodified-Since HTTP::Headers::ActionPack::DateHeader If-Modified-Since HTTP::Headers::ActionPack::DateHeader WWW-Authenticate HTTP::Headers::ActionPack::WWWAuthenticate Authentication-Info HTTP::Headers::ActionPack::AuthenticationInfo Authorization HTTP::Headers::ActionPack::Authorization
new( ?%mappings )
The constructor takes an option hash of header-name to class mappings to add too (or override) the default mappings (see above for details). Each class is expected to have a
new_from_stringmethod which can parse the string representation of the given header and return an object.
This returns the set of mappings in this instance.
This returns the list of supported classes, which is by default the list of classes included in this modules, but it also will grab any additionally classes that were specified in the
Returns an instance of HTTP::Headers::ActionPack::ContentNegotiation.
create( $class_name, $args )
This method, given a
$args, will inflate the value using the class found in the
$argsis a string it will call
$class_name, but if
$argsis an ARRAY ref, it will dereference the ARRAY and pass it to
create_header( $header_name, $header_value )
This method, given a
$header_valuewill inflate the value using the class found in the mappings. If
$header_valueis a string it will call
new_from_stringon the class mapped to the
$header_name, but if
$header_valueis an ARRAY ref, it will dereference the ARRAY and pass it to
inflate( $http_headers )
inflate( $http_request )
inflate( $plack_request )
inflate( $web_request )
Given either a HTTP::Headers instance, a HTTP::Request instance, a Plack::Request instance, or a Web::Request instance, this method will inflate all the relevant headers and store the object in the same instance.
In theory this should not negatively affect anything since all the header objects overload the stringification operator, and most often the headers are treated as strings. However, this is not for certain and care should be taken.
A simple survey of most of the Plack::Handler subclasses shows that most of them will end up properly stringifying these header objects before sending them out. The notable exceptions were the Apache handlers.
At the time of this writing, the solution for this would be for you to either stringify these objects prior to returning your Plack::Response, or to write a simple middleware component that would do that for you. In future versions we might provide just such a middleware (it would likely inflate the header objects on the request side as well).
As mentioned above, all the header objects overload the stringification operator, so normal usage of them should just do what you would expect (stringify in a sensible way). However this is not certain and so care should be taken when passing object headers onto another library that is expecting strings.
Stevan Little <firstname.lastname@example.org>
Andrew Nelson <email@example.com>
Dave Rolsky <firstname.lastname@example.org>
Florian Ragwitz <email@example.com>
Jesse Luehrs <firstname.lastname@example.org>
Karen Etheridge <email@example.com>
This software is copyright (c) 2012 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.