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).



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.

CLASS->new_response( [ CODE ] )

Create a new response header with response code CODE (default: 200 "OK").

Assumes response is HTTP/1.0.


Parse the request URI for querystring parameters.

$obj->add_param( KEY, VALUE )

Add a new param (see $obj->param below).

$obj->param( [ KEY ] )

Returns all params for KEY in LIST context, or the last param for KEY in SCALAR context.

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.


Gets the response code.


Gets the request method (e.g. "GET", "POST", etc).


Gets the request URI. Returns the full URI inclusive of query string.

Also callable as $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.

$obj->cookie( NAME, VALUE [, PARAMS] )

Set the cookie called NAME with 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.

$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.


Returns the very first line of the request as seen.

$obj->header( KEY [, VALUE ] )

Get/Set the value for a given header.


Returns true if the request was a HTTP/0.9 request.


Returns a reference to a string representing the headers in full.


Clone the current header object. Returns a new AxKit2::HTTPHeaders object.

$obj->set_version( VER )

Set the HTTP version using the N.N format.


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?"

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.


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 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.