Mojo::Headers - Headers
use Mojo::Headers; my $headers = Mojo::Headers->new; $headers->content_type('text/plain'); $headers->parse("Content-Type: text/html\n\n"); print "$headers";
Mojo::Headers is a container and parser for HTTP headers.
Mojo::Headers implements the following attributes.
buffer
my $buffer = $headers->buffer; $headers = $headers->buffer(Mojo::ByteStream->new);
The Buffer to use for header parsing, by default a Mojo::ByteStream object.
Mojo::Headers inherits all methods from Mojo::Base and implements the following new ones.
accept_language
my $accept_language = $headers->accept_language; $headers = $headers->accept_language('de, en');
Shortcut for the Accept-Language header.
Accept-Language
accept_ranges
my $ranges = $headers->accept_ranges; $headers = $headers->accept_ranges('bytes');
Shortcut for the Accept-Ranges header.
Accept-Ranges
add
$headers = $headers->add('Content-Type', 'text/plain');
Add one or more header lines.
authorization
my $authorization = $headers->authorization; $headers = $headers->authorization('Basic Zm9vOmJhcg==');
Shortcut for the Authorization header.
Authorization
to_string
build
my $string = $headers->build; my $string = $headers->to_string; my $string = "$headers";
Format headers suitable for HTTP 1.1 messages.
connection
my $connection = $headers->connection; $headers = $headers->connection('close');
Shortcut for the Connection header.
Connection
content_disposition
my $content_disposition = $headers->content_disposition; $headers = $headers->content_disposition('foo');
Shortcut for the Content-Disposition header.
Content-Disposition
content_length
my $content_length = $headers->content_length; $headers = $headers->content_length(4000);
Shortcut for the Content-Length header.
Content-Length
content_range
my $range = $headers->content_range; $headers = $headers->content_range('bytes 2-8/100');
Shortcut for the Content-Range header.
Content-Range
content_transfer_encoding
my $encoding = $headers->content_transfer_encoding; $headers = $headers->content_transfer_encoding('foo');
Shortcut for the Content-Transfer-Encoding header.
Content-Transfer-Encoding
content_type
my $content_type = $headers->content_type; $headers = $headers->content_type('text/plain');
Shortcut for the Content-Type header.
Content-Type
cookie
my $cookie = $headers->cookie; $headers = $headers->cookie('$Version=1; f=b; $Path=/');
Shortcut for the Cookie header.
Cookie
date
my $date = $headers->date; $headers = $headers->date('Sun, 17 Aug 2008 16:27:35 GMT');
Shortcut for the Date header.
Date
expect
my $expect = $headers->expect; $headers = $headers->expect('100-continue');
Shortcut for the Expect header.
Expect
from_hash
$headers = $headers->from_hash({'Content-Type' => 'text/html'});
Parse headers from a hash.
header
my $string = $headers->header('Content-Type'); my @lines = $headers->header('Content-Type'); $headers = $headers->header('Content-Type' => 'text/plain');
Get or replace the current header values. Note that this method is context sensitive and will turn all header lines into a single one in scalar context.
host
my $host = $headers->host; $headers = $headers->host('127.0.0.1');
Shortcut for the Host header.
Host
if_modified_since
my $m = $headers->if_modified_since; $headers = $headers->if_modified_since('Sun, 17 Aug 2008 16:27:35 GMT');
Shortcut for the If-Modified-Since header.
If-Modified-Since
is_done
my $done = $headers->is_done;
Check if header parser is done.
last_modified
my $m = $headers->last_modified; $headers = $headers->last_modified('Sun, 17 Aug 2008 16:27:35 GMT');
Shortcut for the Last-Modified header.
Last-Modified
location
my $location = $headers->location; $headers = $headers->location('http://127.0.0.1/foo');
Shortcut for the Location header.
Location
names
my $names = $headers->names;
Generate a list of all currently defined headers.
origin
my $origin = $headers->origin; $headers = $headers->origin('http://example.com');
Shortcut for the Origin header.
Origin
parse
my $success = $headers->parse("Content-Type: text/foo\n\n");
Parse formatted headers.
proxy_authenticate
my $authenticate = $headers->proxy_authenticate; $headers = $headers->proxy_authenticate('Basic "realm"');
Shortcut for the Proxy-Authenticate header.
Proxy-Authenticate
proxy_authorization
my $proxy_authorization = $headers->proxy_authorization; $headers = $headers->proxy_authorization('Basic Zm9vOmJhcg==');
Shortcut for the Proxy-Authorization header.
Proxy-Authorization
range
my $range = $headers->range; $headers = $headers->range('bytes=2-8');
Shortcut for the Range header.
Range
referrer
my $referrer = $headers->referrer; $headers = $headers->referrer('http://mojolicious.org');
Shortcut for the Referer header, there was a typo in RFC 2068 which resulted in Referer becoming an official header.
Referer
remove
$headers = $headers->remove('Content-Type');
Remove a header.
sec_websocket_key1
my $key1 = $headers->sec_websocket_key1; $headers = $headers->sec_websocket_key1('4 @1 46546xW%0l 1 5');
Shortcut for the Sec-WebSocket-Key1 header.
Sec-WebSocket-Key1
sec_websocket_key2
my $key2 = $headers->sec_websocket_key2; $headers = $headers->sec_websocket_key2('12998 5 Y3 1 .P00');
Shortcut for the Sec-WebSocket-Key2 header.
Sec-WebSocket-Key2
sec_websocket_location
my $location = $headers->sec_websocket_location; $headers = $headers->sec_websocket_location('ws://example.com/demo');
Shortcut for the Sec-WebSocket-Location header.
Sec-WebSocket-Location
sec_websocket_origin
my $origin = $headers->sec_websocket_origin; $headers = $headers->sec_websocket_origin('http://example.com');
Shortcut for the Sec-WebSocket-Origin header.
Sec-WebSocket-Origin
sec_websocket_protocol
my $protocol = $headers->sec_websocket_protocol; $headers = $headers->sec_websocket_protocol('sample');
Shortcut for the Sec-WebSocket-Protocol header.
Sec-WebSocket-Protocol
server
my $server = $headers->server; $headers = $headers->server('Mojo');
Shortcut for the Server header.
Server
set_cookie
my $set_cookie = $headers->set_cookie; $headers = $headers->set_cookie('f=b; Version=1; Path=/');
Shortcut for the Set-Cookie header.
Set-Cookie
set_cookie2
my $set_cookie2 = $headers->set_cookie2; $headers = $headers->set_cookie2('f=b; Version=1; Path=/');
Shortcut for the Set-Cookie2 header.
Set-Cookie2
status
my $status = $headers->status; $headers = $headers->status('200 OK');
Shortcut for the Status header.
Status
to_hash
my $hash = $headers->to_hash; my $hash = $headers->to_hash(arrayref => 1);
Format headers as a hash. Nested arrayrefs to represent multi line values are optional.
trailer
my $trailer = $headers->trailer; $headers = $headers->trailer('X-Foo');
Shortcut for the Trailer header.
Trailer
transfer_encoding
my $transfer_encoding = $headers->transfer_encoding; $headers = $headers->transfer_encoding('chunked');
Shortcut for the Transfer-Encoding header.
Transfer-Encoding
upgrade
my $upgrade = $headers->upgrade; $headers = $headers->upgrade('WebSocket');
Shortcut for the Upgrade header.
Upgrade
user_agent
my $user_agent = $headers->user_agent; $headers = $headers->user_agent('Mojo/1.0');
Shortcut for the User-Agent header.
User-Agent
www_authenticate
my $authenticate = $headers->www_authenticate; $headers = $headers->www_authenticate('Basic "realm"');
Shortcut for the WWW-Authenticate header.
WWW-Authenticate
Mojolicious, Mojolicious::Guides, http://mojolicious.org.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.