AxKit2::HTTPHeaders - HTTP Request and Response header class
This class parses and encapsulates HTTP headers, including the request/response line (e.g. GET / HTTP/1.0).
CLASS->new( STRREF, IS_RESPONSE, IS_LAME )
Construct a new header object from the given STRREF. Assumes the header is a response header if IS_RESPONSE is set. Assumes HTTP/0.9 if IS_LAME is set.
STRREF
IS_RESPONSE
HTTP/0.9
IS_LAME
CLASS->new_response( [ CODE ] )
Create a new response header with response code CODE (default: 200 "OK").
CODE
Assumes response is HTTP/1.0.
$obj->parse_uri
Parse the request URI for querystring parameters.
$obj->add_param( KEY, VALUE )
Add a new param (see $obj->param below).
$obj->param
$obj->param( [ KEY ] )
Returns all params for KEY in LIST context, or the last param for KEY in SCALAR context.
KEY
Returns a list of current params if KEY is not supplied.
$obj->http_code_english( [ CODE ] )
Returns the english equivalent for HTTP response code CODE. If code is not supplied uses the current response code (not valid for request headers).
$obj->code( CODE [, TEXT] )
Sets the response code to CODE with optional TEXT.
TEXT
$obj->response_code
Gets the response code.
$obj->request_method
Gets the request method (e.g. "GET", "POST", etc).
$obj->request_uri
Gets the request URI. Returns the full URI inclusive of query string.
Also callable as $obj->uri.
$obj->uri
$obj->cookie( NAME )
Returns a list of values for the given cookie NAME in LIST context, or the last set cookie for the given cookie NAME in scalar context. Only works on request headers.
NAME
$obj->cookie( NAME, VALUE [, PARAMS] )
Set the cookie called NAME with value VALUE.
VALUE
If value is an arrayref sets a multi-valued cookie.
Optional params are key-value pairs as per the cookie spec, e.g.:
$header->cookie( foo => "bar", path => "/", secure => 1 );
Expiration via expires is not parsed and does not take formats such as "+1d". It is suggested to use max-age instead (as per RFC 2109) which is a timeout in seconds from the current time.
expires
max-age
$obj->filename( [ STRING ] )
Gets/Sets the request filename value.
$obj->mime_type( [ STRING ] )
Gets/Sets the request MIME type.
$obj->path_info( [ STRING ] )
Gets/Sets the request path-info value.
$obj->version_number( [ VER ] )
Gets/Sets the header version number. Uses the form MAJOR * 1000 + MINOR, so HTTP/1.0 will return 1000 and HTTP/0.9 will return 9.
MAJOR * 1000 + MINOR
1000
9
$obj->request_line
Returns the very first line of the request as seen.
$obj->header( KEY [, VALUE ] )
Get/Set the value for a given header.
$obj->lame_request
Returns true if the request was a HTTP/0.9 request.
$obj->to_string_ref
Returns a reference to a string representing the headers in full.
$obj->clone
Clone the current header object. Returns a new AxKit2::HTTPHeaders object.
AxKit2::HTTPHeaders
$obj->set_version( VER )
Set the HTTP version using the N.N format.
N.N
$obj->content_length
Using all available information, attempt to determine the content length of the message body being sent to us.
$obj->req_keep_alive( RESPONSE_HEADERS )
Given $obj is the request headers, answers the question: "should a response to this person specify keep-alive, given the request and the given response?"
$obj
This is used in proxy mode to determine based on the client's request and the backend's response whether or not the response from the proxy (us) should do keep-alive.
For normal responses (should a response be kept alive) see res_keep_alive.
res_keep_alive
$obj->res_keep_alive_options
Determine if an options response from a backend looks like it can do keep-alive.
$obj->res_keep_alive( REQUEST_HEADERS )
Given $obj is the response headers, answers the question: "is the backend expected to stay open?" this is a combination of the request we sent to it and the response they sent...
You don't normally need to call this - it is automatically performed by the backend.
$obj->range( SIZE )
Given a size, returns STATUS, RANGE_START, RANGE_END.
STATUS, RANGE_START, RANGE_END
Status will be one of:
200 - Invalid or non-existant range header. Serve normally.
206 - Parsable range is good. Serve partial content.
416 - Range is unsatisfiable.
To install AxKit2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AxKit2
CPAN shell
perl -MCPAN -e shell install AxKit2
For more information on module installation, please visit the detailed CPAN module installation guide.