GX::HTTP::Headers - HTTP message headers class
# 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" );
This module provides the GX::HTTP::Headers class which extends the GX::Class::Object class.
new
Returns a new GX::HTTP::Headers object.
$headers = GX::HTTP::Headers->new;
$headers ( GX::HTTP::Headers object )
$headers
GX::Exception
Also see parse().
parse()
add
Adds the given value to the specified header field.
$headers->add( $field, $value );
$field ( string )
$field
$value ( string )
$value
Multiple values can be passed as a list:
$headers->add( $field, @values );
@values ( strings )
@values
as_string
Returns the header fields formatted as a HTTP message header.
$string = $headers->as_string;
$string ( string )
$string
clear
Removes all header fields.
$headers->clear;
count
Returns the total number of header fields.
$count = $headers->count;
$count ( integer )
$count
field_names
Returns the names of the header fields.
@fields = $headers->field_names;
@fields ( strings )
@fields
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 );
$value ( string | undef )
undef
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 );
remove
Removes the specified header field.
$result = $headers->remove( $field );
$result ( bool )
$result
set
Same as add(), but replaces any existing values for the specified header field with the ones given.
add()
$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;
content_disposition
Returns / sets the value of the "Content-Disposition" header field.
$value = $headers->content_disposition; $value = $headers->content_disposition( $value );
$value ( string | undef ) [ optional ]
See RFC 2616, section 15.5.
content_encoding
Returns / sets the value of the "Content-Encoding" header field.
$value = $headers->content_encoding; $value = $headers->content_encoding( $value );
See RFC 2616, section 14.11.
content_language
Returns / sets the value of the "Content-Language" header field.
$value = $headers->content_language; $value = $headers->content_language( $value );
See RFC 2616, section 14.12.
content_length
Returns / sets the value of the "Content-Length" header field.
$value = $headers->content_length; $value = $headers->content_length( $value );
See RFC 2616, section 14.13.
content_type
Returns / sets the value of the "Content-Type" header field.
$value = $headers->content_type; $value = $headers->content_type( $value );
See RFC 2616, section 14.17.
date
Returns / sets the value of the "Date" header field.
$value = $headers->date; $value = $headers->date( $value );
See RFC 2616, section 14.18.
expires
Returns / sets the value of the "Expires" header field.
$value = $headers->expires; $value = $headers->expires( $value );
See RFC 2616, section 14.21.
last_modified
Returns / sets the value of the "Last-Modified" header field.
$value = $headers->last_modified; $value = $headers->last_modified( $value );
See RFC 2616, section 14.29.
The following classes inherit directly from GX::HTTP::Headers:
GX::HTTP::Request::Headers
GX::HTTP::Response::Headers
RFC 2616
Jörg A. Uzarek <uzarek@runlevelnull.de>
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.
To install GX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GX
CPAN shell
perl -MCPAN -e shell install GX
For more information on module installation, please visit the detailed CPAN module installation guide.