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
TYPE argument chooses
variations in behaviour:
1. Assume an
2. Create response headers.
3. Create generic request headers without start line, e.g. multipart parts.
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.
Add a new param (see
Remove a query parameter (see
Returns all params for
KEY in LIST context, or the last param for
Returns a list of current params if
KEY is not supplied.
Returns the english equivalent for HTTP response code
CODE. If code is not
supplied uses the current response code (not valid for request headers).
Sets the response code to
CODE with optional
Gets the response code.
Sets/gets the request method (e.g. "GET", "POST", etc).
Gets/sets the authenticated request username, if any.
Gets the request URI. Returns the full URI including query string. The URI is normalized to have minimum neccessary %-encoding as specified by RFC2396. Furthermore %-escapes are normalized to have uppercase hex chars only.
Also callable as
Gets the request URI including host name and port. This URI can be used to build links to the currently running code, or for redirects.
Please be aware that it can yield wrong results in some reverse-proxy setups. Moreover,
this method works like
$obj->uri when no
Host-Header is present.
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
If no name is given, returns a list of cookie names.
Set the cookie called
NAME with 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 );
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.
Gets/Sets the request filename value.
Gets/Sets the request MIME type.
Gets/Sets the request path-info value.
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
Returns the very first line of the request as seen.
Get/Set the value for a given header. If no name is given, returns list of present headers.
Get a parameter value for a given header, for example
Returns undef if
PARAM was not found.
Get value for a given header excluding parameters. This only works for headers that are structured as tokens, not *text.
Remove 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
Set the HTTP version using the
Using all available information, attempt to determine the content length of the message body being sent to us.
$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
Determine if an options response from a backend looks like it can do keep-alive.
$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.
Given a size, returns
STATUS, RANGE_START, RANGE_END.
Status will be one of:
- - Invalid or non-existant range header. Serve normally.
- * 206 - Parsable range is good. Serve partial content.
- * 416 - Range is unsatisfiable.
Sets up response headers to prevent caching by clients and intermediate proxies. This sets several headers to make sure all clients act accordingly, regardless of which HTTP version they implement.
Do not use this for more fine-grained cache control.