| Mojolicious documentation | view source | Contained in the Mojolicious distribution. |
accept_languageaccept_rangesaddauthorizationconnectioncontent_dispositioncontent_lengthcontent_rangecontent_transfer_encodingcontent_typecookiedatedntexpectfrom_hashheaderhostif_modified_sinceis_doneis_limit_exceededlast_modifiedleftoverslocationnamesparseproxy_authenticateproxy_authorizationrangereferrerremovesec_websocket_acceptsec_websocket_keysec_websocket_originsec_websocket_protocolsec_websocket_versionserverset_cookieset_cookie2statusto_hashto_stringtrailertransfer_encodingupgradeuser_agentwww_authenticateMojo::Headers - Headers
use Mojo::Headers;
my $headers = Mojo::Headers->new;
$headers->content_type('text/plain');
$headers->parse("Content-Type: text/html\n\n");
Mojo::Headers is a container and parser for HTTP headers.
Mojo::Headers implements the following attributes.
max_line_sizemy $size = $headers->max_line_size; $headers = $headers->max_line_size(1024);
Maximum line size in bytes, defaults to 10240.
Note that this attribute is EXPERIMENTAL and might change without warning!
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_ranges my $ranges = $headers->accept_ranges;
$headers = $headers->accept_ranges('bytes');
Shortcut for the Accept-Ranges header.
add $headers = $headers->add('Content-Type', 'text/plain');
Add one or more header lines.
authorizationconnection my $connection = $headers->connection;
$headers = $headers->connection('close');
Shortcut for the Connection header.
content_disposition my $content_disposition = $headers->content_disposition;
$headers = $headers->content_disposition('foo');
Shortcut for the Content-Disposition header.
content_lengthmy $content_length = $headers->content_length; $headers = $headers->content_length(4000);
Shortcut for the Content-Length header.
content_range my $range = $headers->content_range;
$headers = $headers->content_range('bytes 2-8/100');
Shortcut for the Content-Range header.
content_transfer_encoding my $encoding = $headers->content_transfer_encoding;
$headers = $headers->content_transfer_encoding('foo');
Shortcut for the Content-Transfer-Encoding header.
content_type my $content_type = $headers->content_type;
$headers = $headers->content_type('text/plain');
Shortcut for the Content-Type header.
cookiedate my $date = $headers->date;
$headers = $headers->date('Sun, 17 Aug 2008 16:27:35 GMT');
Shortcut for the Date header.
dntmy $dnt = $headers->dnt; $headers = $headers->dnt(1);
Shortcut for the DNT (Do Not Track) header.
Note that this method is EXPERIMENTAL and might change without warning!
expect my $expect = $headers->expect;
$headers = $headers->expect('100-continue');
Shortcut for the Expect header.
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.
# Multiple headers with the same name
for my $header ($headers->header('Set-Cookie')) {
print "Set-Cookie:\n";
# Each header contains an array of lines
for my line (@$header) {
print "line\n";
}
}
host my $host = $headers->host;
$headers = $headers->host('127.0.0.1');
Shortcut for the Host header.
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.
is_donemy $done = $headers->is_done;
Check if header parser is done.
is_limit_exceededmy $limit = $headers->is_limit_exceeded;
Check if a header has exceeded max_line_size.
Note that this method is EXPERIMENTAL and might change without warning!
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.
leftoversmy $leftovers = $headers->leftovers;
Leftovers.
location my $location = $headers->location;
$headers = $headers->location('http://127.0.0.1/foo');
Shortcut for the Location header.
namesmy $names = $headers->names;
Generate a list of all currently defined headers.
parse $headers = $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_authorizationrange my $range = $headers->range;
$headers = $headers->range('bytes=2-8');
Shortcut for the Range header.
referrer my $referrer = $headers->referrer;
$headers = $headers->referrer('http://mojolicio.us');
Shortcut for the Referer header, there was a typo in RFC 2068 which
resulted in Referer becoming an official header.
remove $headers = $headers->remove('Content-Type');
Remove a header.
sec_websocket_accept my $accept = $headers->sec_websocket_accept;
$headers = $headers->sec_websocket_accept('s3pPLMBiTxaQ9kYGzzhZRbK+xOo=');
Shortcut for the Sec-WebSocket-Accept header.
sec_websocket_key my $key = $headers->sec_websocket_key;
$headers = $headers->sec_websocket_key('dGhlIHNhbXBsZSBub25jZQ==');
Shortcut for the Sec-WebSocket-Key header.
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_protocol my $protocol = $headers->sec_websocket_protocol;
$headers = $headers->sec_websocket_protocol('sample');
Shortcut for the Sec-WebSocket-Protocol header.
sec_websocket_versionmy $version = $headers->sec_websocket_version; $headers = $headers->sec_websocket_version(8);
Shortcut for the Sec-WebSocket-Version header.
server my $server = $headers->server;
$headers = $headers->server('Mojo');
Shortcut for the Server header.
set_cookieset_cookie2status my $status = $headers->status;
$headers = $headers->status('200 OK');
Shortcut for the Status header.
to_hashmy $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.
to_stringmy $string = $headers->to_string;
Format headers suitable for HTTP 1.1 messages.
trailer my $trailer = $headers->trailer;
$headers = $headers->trailer('X-Foo');
Shortcut for the Trailer header.
transfer_encoding my $transfer_encoding = $headers->transfer_encoding;
$headers = $headers->transfer_encoding('chunked');
Shortcut for the Transfer-Encoding header.
upgrade my $upgrade = $headers->upgrade;
$headers = $headers->upgrade('WebSocket');
Shortcut for the Upgrade header.
user_agent my $user_agent = $headers->user_agent;
$headers = $headers->user_agent('Mojo/1.0');
Shortcut for the User-Agent header.
www_authenticate my $authenticate = $headers->www_authenticate;
$headers = $headers->www_authenticate('Basic "realm"');
Shortcut for the WWW-Authenticate header.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
| Mojolicious documentation | view source | Contained in the Mojolicious distribution. |