NAME
GX::HTTP::Headers - HTTP message headers class
SYNOPSIS
# Load the class
use GX::HTTP::Headers;
# Create a new headers object
$headers = GX::HTTP::Headers->new;
# Set the value of a header field
$headers->set( 'Content-Type' => 'text/plain' );
# Get the value of a header field
$content_type = $headers->get( 'Content-Type' );
# Print the headers
print $headers->as_string;
# Parse a HTTP message header
$headers->parse(
"Content-Length: 26971\015\012" .
"Content-Type: text/html\015\012" .
"Date: Fri, 02 Oct 2009 12:05:02 GMT"
);
DESCRIPTION
This module provides the GX::HTTP::Headers class which extends the GX::Class::Object class.
METHODS
Constructor
new
Returns a new GX::HTTP::Headers object.
$headers = GX::HTTP::Headers->new;
- Returns:
-
$headers( GX::HTTP::Headers object )
- Exceptions:
Also see parse().
Basic Public API
add
Adds the given value to the specified header field.
$headers->add( $field, $value );
Multiple values can be passed as a list:
$headers->add( $field, @values );
as_string
Returns the header fields formatted as a HTTP message header.
$string = $headers->as_string;
clear
Removes all header fields.
$headers->clear;
count
Returns the total number of header fields.
$count = $headers->count;
field_names
Returns the names of the header fields.
@fields = $headers->field_names;
get
Returns the values of the specified header field in the order they were added.
@values = $headers->get( $field );
In scalar context, the first of those values is returned.
$value = $headers->get( $field );
parse
Parses the given message header and adds the resulting header field / value pairs to the container.
$headers->parse( $string );
This method can also be used as a constructor.
$headers = GX::HTTP::Headers->parse( $string );
- Arguments:
-
$string( string )
- Returns:
-
$headers( GX::HTTP::Headers object )
- Exceptions:
remove
Removes the specified header field.
$result = $headers->remove( $field );
set
Same as add(), but replaces any existing values for the specified header field with the ones given.
$headers->set( $field, $value );
$headers->set( $field, @values );
sorted_field_names
Returns the names of the header fields, sorted as suggested by RFC 2616.
@fields = $headers->sorted_field_names;
Public Field Accessors
content_disposition
Returns / sets the value of the "Content-Disposition" header field.
$value = $headers->content_disposition;
$value = $headers->content_disposition( $value );
content_encoding
Returns / sets the value of the "Content-Encoding" header field.
$value = $headers->content_encoding;
$value = $headers->content_encoding( $value );
content_language
Returns / sets the value of the "Content-Language" header field.
$value = $headers->content_language;
$value = $headers->content_language( $value );
content_length
Returns / sets the value of the "Content-Length" header field.
$value = $headers->content_length;
$value = $headers->content_length( $value );
content_type
Returns / sets the value of the "Content-Type" header field.
$value = $headers->content_type;
$value = $headers->content_type( $value );
date
Returns / sets the value of the "Date" header field.
$value = $headers->date;
$value = $headers->date( $value );
expires
Returns / sets the value of the "Expires" header field.
$value = $headers->expires;
$value = $headers->expires( $value );
last_modified
Returns / sets the value of the "Last-Modified" header field.
$value = $headers->last_modified;
$value = $headers->last_modified( $value );
SUBCLASSES
The following classes inherit directly from GX::HTTP::Headers:
SEE ALSO
AUTHOR
Jörg A. Uzarek <uzarek@runlevelnull.de>
COPYRIGHT AND LICENSE
Copyright (c) 2009-2011 Jörg A. Uzarek.
This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.