Skip to content

Latest commit

 

History

History
929 lines (592 loc) · 24.5 KB

File metadata and controls

929 lines (592 loc) · 24.5 KB

NAME

HTTP::Headers - HTTP ��<����祉�若�吾�������������˨����祉�������������壔�í�

SYNOPSIS

require HTTP::Headers;
$h = HTTP::Headers->new;

$h->header('Content-Type' => 'text/plain');  # set
$ct = $h->header('Content-Type');            # get
$h->remove_header('Content-Type');           # delete

DESCRIPTION

HTTP::Headers ��壔�í�鴻�� HTTP 綵√����<����祉�若�吾�������������˨����祉����������障����� �����������壔����c�若�˨����������若�違�����絮����-��ゃ�勛����水����������ф���������������������� 膵違��菴���������������������ャ����������劫����勰��綺���у�阪����������障����� �����c�若�˨�������壠ぇ���絖�絨����絖������∴�������障�����

�����勉�壔�í�鴻�勉�ゃ�潟�鴻�帥�潟�鴻�奝��絽吾��HTTP::Request ��� HTTP::Response ��壔�í�鴻�勉�<�潟��紊���違�������⓾����í�ゃ����í�ɱ����◐���� 篏������������障�����

篁ヤ����勉�<�純����������ñ����с����障��鐚�

$h = HTTP::Headers->new

��違����� HTTP::Headers ��ŝ����吾�с�壔�����腟���睡����⓾�障����� ��潟�潟�鴻����í�壔�帥�勉����í�<�若�帥����������☗�������勐�����-��ゃ�勛�����羝<�������������堺�ャ�障����� 箴�������:

$h = HTTP::Headers->new(
      Date         => 'Thu, 03 Feb 1994 00:00:00 GMT',
      Content_Type => 'text/html; version=3.2',
      Content_Base => 'http://www.perl.org/');

��潟�潟�鴻����í�壔�帥�勐����違�壔��緇�菴違����� header ��<�純��������羝<�������障�����

$h->clone

HTTP::Headers ��ŝ����吾�с�壔����勉�潟����若��菴������障�����

$h->header( $field )
$h->header( $field => $value )
$h->header( $f1 => $v1, $f2 => $v2, ... )

��蚊����ゃ�障����虁����違�勉�������������c�若�˨����勐�ゃ�����緇������������虁┃絎������障����� ��������������c�若�˨�����($field)��壠ぇ���絖�絨����絖������阪�ャ����障�������� => 羲�膊�絖���勐����˨�壔�í�若�������������ŝ�� Perl ��⓾�若�吟�̥亜�����ŝ�������˨����������������с� '-' ��勌撮��������������� '_' ���篏帥�������������堺�ャ�障�����

header() ��<�純�������虁����違�卡��$field => $values) ��勛�������������������勉�с�� 1 �����勐�若�喝�冴����с�������������勉����c�若�˨�������贋�違����������������堺�ャ�障�����

$value 綣���違�壩�勰����勖��絖������障����虁����違�勐�ゃ�������ゃ����c�若�˨����勉������� ���絖������勉�ŝ�鴻����吾�勉�ŝ����<�㋘�潟�鴻�˨����������������с����障����� $value 綣���違�� undef ��勐�翫����������c�若�˨����壠����ゃ�������障����� $value ������絎���������ŝ�������違����������壠����眼�������障��������

���緇���勉�������������c�若�˨����勐𡉴����� (��障����壠��) ���菴���������障����� �����勉�������ŝ����c�若�˨�������ŝ����翫����壔��undef ���菴���������障�����

茲���違�勐�ゃ�������ゃ����c�若�˨����壔�� ��ŝ�鴻����潟�潟����㏍�鴻����с�壠�ャ����勐�ゃ�������☀����������� ��鴻�˨�í�潟�潟����㏍�鴻����с�� ", " �����阪��������絖���������⓾�ゃ�ŝ����������障����� HTTP 篁�罕� (RFC 2616) ��с�壔�������勖�号����ц����違�勐�ゃ��腟���������⓾����������� �����c�若�˨����勖����潟�壠����������ŝ�����������膣���������⓾����障��������絎������˨� ��у����� Netscape ��壔����㏍��(HTTP::Cookies ������)��勉�������˨��筝���ゃ� �����c�若�˨����勐�ゃ�勖��羈���勌�������������� "," ���篏帥�c�⓾�������翫�������������障�����

箴�:

$header->header(MIME_Version => '1.0',
                 User_Agent   => 'My-Web-Client/0.01');
$header->header(Accept => "text/html, text/plain, image/*");
$header->header(Accept => [qw(text/html text/plain image/*)]);
@accepts = $header->header('Accept');  # get multiple values
$accepts = $header->header('Accept');  # get values as a single string
$h->push_header( $field => $value )
$h->push_header( $f1 => $v1, $f2 => $v2, ... )

���絎������������������������違����������c�若�˨����勐�ゃ��菴遵�������障����� �����������c�若�˨����勌札�����勐�ゃ�壩�������障�����

header() ��<�純�������̹�≪����⓾�壔�������c�若�˨����� ($field) ��壠ぇ���絖�絨����絖��� ��≫����ŝ�����'-' ��勌撮��������������� '_' ���篏帥����障�����

$value 綣���違�˨�壔�鴻�˨�í����鴻�˨�í�勉�ŝ�鴻����吾�勉�ŝ����<�㋘�潟�鴻�����絎���������������� ��堺�ャ�障�����

$header->push_header(Accept => 'image/jpeg');
$header->push_header(Accept => [map "image/$_", qw(gif png tiff)]);
$h->init_header( $field => $value )

���絎���������������������˨����с����ゃ����祉�������������⓾����ŝ����翫����勉�帥��筝���������������ゃ�� ��祉����������障�����

��������������c�若�˨����� ($field) ��壠ぇ���絖�絨����絖���奝�≫����ŝ�����'-' ��勌撮�������������� '_' ���篏帥����障�����

$value 綣���違�壔����鴻�˨�í�������鴻�˨�í�勉�ŝ�鴻����吾�勉�ŝ����<�㋘�潟�鴻����������障�����

$h->remove_header( $field, ... )

�����勰�∽�違�壩��絎������������������������ゃ�������������c�若�˨����������ゃ����障�����

��������������c�若�˨����� ($field) ��壠ぇ���絖�絨����絖���奝�≫����ŝ�����'-' ��勌撮�������������� '_' ���篏帥����障�����

菴������ゃ�壔�������ゃ�������������c�若�˨����勐�ゃ�с����� ��鴻�˨�ï坨�������㏍�鴻����с�壔�������ゃ�������������c�若�˨����勖�違��菴���������障�����

茲���違�勉����c�若�˨��������羝<�������翫�����菴������ゃ�勐����í�������í�勉����c�若�˨���� ��ゃ�с����c����������ャ����������壚����㋜����˨�壔�с����ŝ�����������羈���������⓾��������������

$h->remove_content_headers

��������壔����<����祉�若�吾�勐��絎鴻��荐�菴違�������������˩戎��������⓾����������⓾� ��������������c�若�˨����������ゃ����障����� �����c�若�˨�������勰�㏍�� Content- ���篁���������⓾�勉����c�若�˨�������� Allow, Expires, Last-Modified �����c�若�˨�����絲乗院�����ŝ����障����� RFC 2616 ��с�壔����������勉����c�若�˨����� Entity Header Fields �� ���篁������������⓾����障�����

菴������ゃ�壔�������ゃ�������������������勉�帥����˨����違����� HTTP::Headers ��ŝ����吾�с�壔����с�����

$h->clear

��������壠����⓾�勉�������������c�若�˨����������ゃ����障�����

$h->header_field_names

�����������˨����������c�若�˨�������勰��茲������ゃ�������ŝ�鴻�����菴������障����� �����c�若�˨�������� HTTP 篁�罕���фィ絅���������⓾��������������紊ф��絖�絨����絖����篆���������⓾����⓾�� �ィ��⓾�������⓾����� "Good Practice" �����ц����������障�����

��鴻�˨�í�潟�潟����㏍�鴻����с�奝��茲������ゃ����������c�若�˨�������勖�違��菴������障�����

$h->scan( \&process_header_field )

�����������������c�若�˨����������������˨�泣����˨�若����潟����ñ�������障����� ��潟�若�˨�������壔�˨�若����潟�� 2 綣���違�у�若�喝�冴�������障��鐚������c�若�˨������� 1 ��ゃ�勐��(���絖����)��с����� ��������������c�若�˨�����茲���違�勐�ゃ�������c�⓾�������違����˨�若����潟�壔�������������勐�ゃ�˨�ゃ�� 1 �����若�違����障����� ��潟�若�˨�������壔�˨�若����潟��羝<�������������c�若�˨������� HTTP 篁�罕���ф��罅���������⓾�����紊ф��絖�鐚鎞����絖���������<���ィ絅���������⓾����� "Good Practice" ��勰����с����c�⓾����障�����

��潟�若�˨�������壔�˨�若����潟�������勤�������ゃ�壠����☎�∴����������障����� ��˨�若����壚��紊� (die) ��勛�榊����˨����c�☎��篋���������翫�������������障�������� scan() ��勐�若�喝�冴�������壚��紊������ɱ����ʃ昆��с����í�����������綽�荀������������障�����

$h->as_string
$h->as_string( $eol )

�����í�若����������������� MIME �����������������⓾�������������c�若�˨�����菴������障����� ���絖�������腟���睡����⓾�������������������� scan ��<�純��������篏帥�c�⓾�������勉�с��腟������ HTTP 篁�罕���ф��罅���������⓾�����紊ф��絖�絨����絖���с����������������c�若�˨����勰��綺��� �ィ絅���������⓾����� "Good Practice" ���緇������障����� ��激�������������勐�ゃ�壔�������障����障��������

��ŝ����激�с�潟�� $eol �����í�<�若�帥�壚戎���������茵���˨�激�若�宴�潟�鴻�����絎������障����� ��������í�˨����� "\n" ��с����� ��������������c�若�˨����勐�ゃ��������莨若�障����� "\n" ���絖���壔�������勤����˨�激�若�宴�潟�鴻� 臀勉����������������障�����

CONVENIENCE METHODS

(箴水�í�<�純�����)

��������ñ����������������������壚札筝���勌梢��í�<�純����������������⓾����≪�壔�祉�鴻�с����障����� �����������勉�<�純�������勉�祉����������壔����������勐�ゃ��茯㏍�������◑┃絎���������������勌検��鴻� 篏帥����������с����障����� ��<�純��������綣���違��羝<����違����������勐�ゃ��荐㊤����������障����� �����������勐𡉴����ゃ�壠幻��̬����������障����� 筝�������������������������絖���������ŝ����翫����壔��undef ���菴���������障�����

��ヤ��/�����祉����宴����<�純�������壠幻��˨����勐�ゃ����激�鴻�����������(1970 綛� 1 ��� 1 ��ャ������� 腱����)���紊���������������������勐�ゃ��荐㊤�������������翫����˨�壔����ゃ��������������腮勰����с�������������� ���緇������障�����

$h->date

�����勉����������壔�<����祉�若�吾����肴�������������ヤ����������祉��茵������障����� 箴�������:

$h->date(time);  # set current date
$h->expires

�����勉����������壔��������篁ラ����壔����勉����潟����ŝ����育佈��с�ŝ��(stale)��с�������◑�������������� ��ヤ����������祉��腓冴����障�����

$h->if_modified_since
$h->if_unmodified_since

�����������������������c�若�˨����壔�ŝ�壔����鴻�������>散篁������˨����障����� ��������ŝ�壔����鴻�������������ŝ�純�若�鴻�������勉����c�若�˨����ф��絎���������������祉�����紊���眼�������� (�����������壠����眼�������⓾����ŝ��)��ŝ�������泣�若����壩����梧�ʃ昆��勌撮����� 304 Not Modified ��㋘�鴻����潟�鴻��菴������障�����

$h->last_modified

�����勉����������壔����勉�ŝ�純�若�鴻�����緇����紊���眼����������ヤ����������祉��菴������障����� 箴�������:

# check if document is more than 1 hour old
if (my $last_mod = $h->last_modified) {
    if ($last_mod < time - 60*60) {
          ...
    }
}
$h->content_type

Content-Type ��������������c�若�˨����壔�<����祉�若�後��絎鴻�勉�<����c�≪�帥�ゃ�����腓冴����障����� 箴�������:

$h->content_type('text/html');

菴������������ゃ�壠�����絖����紊�������������羹���◐����ŝ����í�<�若�帥����������純����������� ��������潟�潟����㏍�鴻����с�������違�������������������ゃ�������☀����������障����� �����勉�������ŝ�������������c�若�˨�������ŝ����翫�����腥堺��絖�������菴���������障����� ��������壚札筝���勉�������˨��������������絎������˨����障��:

if ($h->content_type eq 'text/html') {
   # we enter this place even if the real header value happens to
   # be 'TEXT/HTML; version=3.0'
   ...
}
$h->content_type_charset

Content-Type ���������������絎���������⓾�����紊ф��絖�������������絖����������菴������障����� ��ŝ�鴻����潟�潟����㏍�鴻����с�壔��絨����絖����������茖吾�勉�潟�潟����潟����帥�ゃ�����綣����膓������ 紊ф��絖�������������絖����������菴������障����� ��í�<�����������������������絎���������⓾����ŝ�������� undef ��˨�ŝ����障�����

$h->content_is_text

���絎鴻�������㏍�鴻����с�������������� Content-Type ��������������c�若�˨�����腓冴����⓾�������翫����� ������菴������障�����

$h->content_is_html

���絎鴻�� (XHTML �����˨��) ������腮勉�� HTML ��с�������������� Content-Type ��������������c�若�˨�����腓冴����⓾�������翫�����������菴������障����� �����勉�<�純�������� Content-Type ���荐㊤����������勉�˨�壚戎�����障��������

$h->content_is_xhtml

���絎鴻�� XHTML ��с�������������� Content-Type ��������������c�若�˨�����腓冴����⓾�������翫����� ������菴������障����� �����勉�<�純�������� Content-Type ���荐㊤����������勉�˨�壚戎�����障��������

$h->content_is_xml

���絎鴻�� XML ��с�������������� Content-Type ��������������c�若�˨�����腓冴����⓾�������翫����� ������菴������障����� �����勉�<�純�������� Content-Type ���荐㊤����������勉�˨�壚戎�����障��������

$h->content_encoding

Content-Encoding ��������������c�若�˨����壔�<����c�≪�帥�ゃ����勌信蕋上���������� 篏帥�������障����� ��������������違�������勐�ゃ�壔�í����ʃ申�����勉����潟�潟�若����c�潟�井����純�������勉�ŝ�純�若�鴻� ��ñ�������������勉�����腓冴����障�����

$h->content_length

��<����祉�若�後��絎鴻�勐ぇ��������������ゃ����違�хず��� 10 ��我�違��

$h->content_language

��<����祉�若�後��絎鴻��絲乗院��������⓾����������������勤�ɾ�区��茯���� �����勐�ゃ�� RFC1766 ��у��臂í�������⓾����� 1 ��ゃ�障����虁����違�勤��茯���帥�違�с����� 箴������� "no" ��壚����������勉����˨�⓾�с�取�����"en-US" �� ��≪�<�ŝ�˨�т戎��������⓾�������沿����с�����

$h->title

�����吾�勉�帥�ゃ����˨�� libwww-perl ��с�壔�������勉����������虁�ɱ�������� HTML �����吾� <TITLE>...</TITLE> 荀�膣������������������������障����� �����勉����������壔����壔�� HTTP 罔�羣���勌�������с�壔�������障��������

$h->user_agent

�����勉����������壔�ŝ�壔����鴻����<����祉�若�吾�т戎��������������勉�ŝ�壔����鴻�������肴�������� ��⓾�若�吟����若�吾�с�潟����˨�ゃ����⓾�勖����宴����ャ�c�⓾����障����� 箴�������:

$h->user_agent('Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0)');
$h->server

server ��������������c�若�˨����˨�壔�������勉�ŝ�壔����鴻�������������宴�� ��泣�若�������㏍�違�í����˨����c�☖戎�����������純�������⓾�с�≪�˨�ゃ����⓾�勖����宴����ャ�c�⓾����障�����

$h->from

�����勉����������˨�壔�ŝ�壔����鴻�������⓾�������⓾�若�吟����若�吾�с�潟�������九勝�����⓾�����篋冴�勉������� ��ゃ�潟�帥�若�������� e-mail ��≪����㋘�鴻����ャ�c�⓾����ŝ�������違�ŝ����障�������� �����勉�≪����㋘�鴻�壔��RFC822 ��˨����c�☗��臂í�������⓾�������������˨��罘�罌違� 篏帥����ŝ�������違�ŝ����障�������� 箴�������:

$h->from('King Kong <king@kong.com>');

�����勉����������壔����壔�� HTTP 罔�羣���勌�������с�壔�������障��������

$h->referer

��������������ŝ�壔����鴻�������������ŝ�純�若�鴻�≪����㋘�鴻�����緇������������������吾� ��≪����㋘�� (URI) ������絎���������������˩戎��������障�����

"Free On-line Dictionary of Computing" ��с�壔��referer ��˨�ゃ���� 篁ヤ����勉����������吾�������⓾����障��:

<World-Wide Web> A misspelling of "referrer" which
somehow made it into the {HTTP} standard.  A given {web
page}'s referer (sic) is the {URL} of whatever web page
contains the link that the user followed to the current
page.  Most browsers pass this information as part of a
request.

(1998-10-19)

筝���㋜����ʒ��荀���˨��������referrer ��������勉�<�純�������吾�勐�ュ���������� 絖���������⓾�������勉�с�������㏍�違�í�������˨�鴻����˨����鴻����������������ŝ�����罩c���� ���篆<�������������������с����障�����

��ŝ����<�í��荐㊤����������������˨�������勉�<�純�������� RFC2616 ��ф��腓冴�������⓾������������� URI 筝㏍�˨����í�違�<�潟����������c����翫����壔����������ゅサ�����障����� ��ŝ����<�í��荐㊤����������������� header(), push_header(), init_header() ���篏帥�������������勰�ゅサ篏�罐㏍� ��ɱ�������˨�� 茵���������ŝ�� ���������羈���������⓾��������������

$h->www_authenticate

�����勉����������� 401 Unauthorized ��㋘�鴻����潟�鴻�勌������������� ��ャ����ŝ�������違�ŝ����障�������� �����c�若�˨����勐�ゃ�壔����ŝ�壔����鴻����������� URI ��檎�ñ����с����� 茯�荐若�鴻�㏍�若����������í�<�若�帥��腓冴�������c�㋘�潟�吾�˨�����罕������������障�����

$h->proxy_authenticate

�����勉����������� 407 Proxy Authentication Required ��㋘�鴻����潟�鴻� ��ャ����ŝ�������違�ŝ����障��������

$h->authorization
$h->proxy_authorization

��泣�若����障����壔����㏍�㏍�激�с�������ʃ昆���茯�荐若����〠⓲��������⓾�若�吟����若�吾�с�潟����壔�� �����������勉�������������ャ�������������˨�������������ŝ����������������障��������

$h->authorization_basic

�����勉����������壔����堺�㋝��荐惹����純�����篏帥��茯�荐若��������������緇���������活┃絎��������������� 篏帥�������障����� ��������潟�潟����㏍�鴻����с�� 2 ��ゃ�勐�ゃ��菴������障��; ��⓾�若�九����������鴻�壔�若����с����� ��鴻�˨�í�潟�潟����㏍�鴻����с�� 1 ��ゃ�勖��絖������������� "uname:password" ���菴������障�����

�����������勐�ゃ��荐㊤����������������˩戎�����������������壔��鐚���ゃ�勐����違�����緇���������障����� 箴�������:

$h->authorization_basic($uname, $password);

������ $uname ��˨�潟�㏍�� ':' �����ャ�c�⓾�������� croak �����障�����

$h->proxy_authorization_basic

authorization_basic() ������罕���с�������� ���������篁c�������� "Proxy-Authorization" ������������荐㊤�������障�����

NON-CANONICALIZED FIELD NAMES

��������������c�若�˨�������壔�����絽�('_' ������ '-' ��吾�勐����������˨�����)罩h�������������障����� �����������ï����с�ŝ����≪����ŝ�宴�若�激�с�潟����������障����� �����c�若�˨�������勐����㏍�� ':' ���篁���������������с��罩h����������ŝ����������˨����������������с����障����� 箴������違�������� "Foo-Bar" ��с�壔�ŝ����㋚����� foo_bar ��������������c�若�˨������� �����������˨����������翫����壔��篁ヤ����勉�������˨����障��:

$h->header(":foo_bar" => 1);

�����������勉����c�若�˨�������壔��$h->header_field_names ��� $h->scan �� ��潟�若�˨�������壔�с�壔����勉�障�� ':' 篁������ц����������障�������� $h->as_string ��с�壔�潟�㏍�潟�虁;腓冴�������障��������

COPYRIGHT

Copyright 1995-2005 Gisle Aas.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.