⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headers.pm

📁 美国CMU大学开发的操作系统健壮性评测软件
💻 PM
📖 第 1 页 / 共 2 页
字号:
=item $h->cloneReturns a copy of this HTTP::Headers object.=back=head1 CONVENIENCE METHODSThe most frequently used headers can also be accessed through thefollowing convenience methods.  These methods can both be used to readand to set the value of a header.  The header value is set if you passan argument to the method.  The old header value is always returned.Methods that deal with dates/times always convert their value to systemtime (seconds since Jan 1, 1970) and they also expect this kind ofvalue when the header value is set.=over 4=item $h->dateThis header represents the date and time at which the message wasoriginated. I<E.g.>:  $h->date(time);  # set current date=item $h->expiresThis header gives the date and time after which the entity should beconsidered stale.=item $h->if_modified_since=item $h->if_unmodified_sinceThis header is used to make a request conditional.  If the requestedresource has (not) been modified since the time specified in this field,then the server will return a C<"304 Not Modified"> response instead ofthe document itself.=item $h->last_modifiedThis header indicates the date and time at which the resource was lastmodified. I<E.g.>:  # check if document is more than 1 hour old  if ($h->last_modified < time - 60*60) {	...  }=item $h->content_typeThe Content-Type header field indicates the media type of the messagecontent. I<E.g.>:  $h->content_type('text/html');The value returned will be converted to lower case, and potentialparameters will be chopped off and returned as a separate value if inan array context.  This makes it safe to do the following:  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'     ...  }=item $h->content_encodingThe Content-Encoding header field is used as a modifier to themedia type.  When present, its value indicates what additionalencoding mechanism has been applied to the resource.=item $h->content_lengthA decimal number indicating the size in bytes of the message content.=item $h->content_languageThe natural language(s) of the intended audience for the messagecontent.  The value is one or more language tags as defined by RFC1766.  Eg. "no" for Norwegian and "en-US" for US-English.=item $h->titleThe title of the document.  In libwww-perl this header will beinitialized automatically from the E<lt>TITLE>...E<lt>/TITLE> elementof HTML documents.  I<This header is no longer part of the HTTPstandard.>=item $h->user_agentThis header field is used in request messages and contains informationabout the user agent originating the request.  I<E.g.>:  $h->user_agent('Mozilla/1.2');=item $h->serverThe server header field contains information about the software beingused by the originating server program handling the request.=item $h->fromThis header should contain an Internet e-mail address for the humanuser who controls the requesting user agent.  The address should bemachine-usable, as defined by RFC822.  E.g.:  $h->from('Gisle Aas <aas@sn.no>');=item $h->refererUsed to specify the address (URI) of the document from which therequested resouce address was obtained.=item $h->www_authenticateThis header must be included as part of a "401 Unauthorized" response.The field value consist of a challenge that indicates theauthentication scheme and parameters applicable to the requested URI.=item $h->proxy_authenticateThis header must be included in a "407 Proxy Authentication Required"response.=item $h->authorization=item $h->proxy_authorizationA user agent that wishes to authenticate itself with a server or aproxy, may do so by including these headers.=item $h->authorization_basicThis method is used to get or set an authorization header that use the"Basic Authentication Scheme".  In array context it will return twovalues; the user name and the password.  In scalar context it willreturn I<"uname:password"> as a single string value.When used to set the header value, it expects two arguments.  I<E.g.>:  $h->authorization_basic($uname, $password);The method will croak if the $uname contains a colon ':'.=item $h->proxy_authorization_basicSame as authorization_basic() but will set the "Proxy-Authorization"header instead.=back=head1 COPYRIGHTCopyright 1995-1998 Gisle Aas.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=cut1;#__DATA__sub clone{    my $self = shift;    my $clone = new HTTP::Headers;    $self->scan(sub { $clone->push_header(@_);} );    $clone;}sub push_header{    Carp::croak('Usage: $h->push_header($field, $val)') if @_ != 3;    shift->_header(@_, 'PUSH');}sub remove_header{    my($self, @fields) = @_;    my $field;    foreach $field (@fields) {	$field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;	delete $self->{lc $field};    }}# Convenience access functionssub _date_header{    require HTTP::Date;    my($self, $header, $time) = @_;    my($old) = $self->_header($header);    if (defined $time) {	$self->_header($header, HTTP::Date::time2str($time));    }    HTTP::Date::str2time($old);}sub date                { shift->_date_header('Date',                @_); }sub expires             { shift->_date_header('Expires',             @_); }sub if_modified_since   { shift->_date_header('If-Modified-Since',   @_); }sub if_unmodified_since { shift->_date_header('If-Unmodified-Since', @_); }sub last_modified       { shift->_date_header('Last-Modified',       @_); }# This is used as a private LWP extention.  The Client-Date header is# added as a timestamp to a response when it has been received.sub client_date         { shift->_date_header('Client-Date',         @_); }# The retry_after field is dual format (can also be a expressed as# number of seconds from now), so we don't provide an easy way to# access it until we have know how both these interfaces can be# addressed.  One possibility is to return a negative value for# relative seconds and a positive value for epoch based time values.#sub retry_after       { shift->_date_header('Retry-After',       @_); }sub content_type      {  my $ct = (shift->_header('Content-Type', @_))[0];  return '' unless defined($ct) && length($ct);  my @ct = split(/\s*;\s*/, lc($ct));  wantarray ? @ct : $ct[0];}sub title             { (shift->_header('Title',            @_))[0] }sub content_encoding  { (shift->_header('Content-Encoding', @_))[0] }sub content_language  { (shift->_header('Content-Language', @_))[0] }sub content_length    { (shift->_header('Content-Length',   @_))[0] }sub user_agent        { (shift->_header('User-Agent',       @_))[0] }sub server            { (shift->_header('Server',           @_))[0] }sub from              { (shift->_header('From',             @_))[0] }sub referer           { (shift->_header('Referer',          @_))[0] }sub warning           { (shift->_header('Warning',          @_))[0] }sub www_authenticate  { (shift->_header('WWW-Authenticate', @_))[0] }sub authorization     { (shift->_header('Authorization',    @_))[0] }sub proxy_authenticate  { (shift->_header('Proxy-Authenticate',  @_))[0] }sub proxy_authorization { (shift->_header('Proxy-Authorization', @_))[0] }sub authorization_basic       { shift->_basic_auth("Authorization",       @_) }sub proxy_authorization_basic { shift->_basic_auth("Proxy-Authorization", @_) }sub _basic_auth {    require MIME::Base64;    my($self, $h, $user, $passwd) = @_;    my($old) = $self->_header($h);    if (defined $user) {	Carp::croak("Basic authorization user name can't contain ':'")	  if $user =~ /:/;	$passwd = '' unless defined $passwd;	$self->_header($h => 'Basic ' .                             MIME::Base64::encode("$user:$passwd", ''));    }    if (defined $old && $old =~ s/^\s*Basic\s+//) {	my $val = MIME::Base64::decode($old);	return $val unless wantarray;	return split(/:/, $val, 2);    }    return;}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -