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

📄 headers.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
 $h = HTTP::Headers->new; $h->header('Content-Type' => 'text/plain');  # set $ct = $h->header('Content-Type');            # get $h->remove_header('Content-Type');           # delete=head1 DESCRIPTIONThe C<HTTP::Headers> class encapsulates HTTP-style message headers.The headers consist of attribute-value pairs also called fields, whichmay be repeated, and which are printed in a particular order.  Thefield names are cases insensitive.Instances of this class are usually created as member variables of theC<HTTP::Request> and C<HTTP::Response> classes, internal to thelibrary.The following methods are available:=over 4=item $h = HTTP::Headers->newConstructs a new C<HTTP::Headers> object.  You might pass some initialattribute-value pairs as parameters to the constructor.  I<E.g.>: $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/');The constructor arguments are passed to the C<header> method which isdescribed below.=item $h->cloneReturns a copy of this C<HTTP::Headers> object.=item $h->header( $field )=item $h->header( $field => $value, ... )Get or set the value of one or more header fields.  The header fieldname ($field) is not case sensitive.  To make the life easier for perlusers who wants to avoid quoting before the => operator, you can use'_' as a replacement for '-' in header names.The header() method accepts multiple ($field => $value) pairs, whichmeans that you can update several fields with a single invocation.The $value argument may be a plain string or a reference to an arrayof strings for a multi-valued field. If the $value is provided asC<undef> then the field is removed.  If the $value is not given, thenthat header field will remain unchanged.The old value (or values) of the last of the header fields is returned.If no such field exists C<undef> will be returned.A multi-valued field will be returned as separate values in listcontext and will be concatenated with ", " as separator in scalarcontext.  The HTTP spec (RFC 2616) promise that joining multiplevalues in this way will not change the semantic of a header field, butin practice there are cases like old-style Netscape cookies (seeL<HTTP::Cookies>) where "," is used as part of the syntax of a singlefield value.Examples: $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=item $h->push_header( $field => $value )Add a new field value for the specified header field.  Previous valuesfor the same field are retained.As for the header() method, the field name ($field) is not casesensitive and '_' can be used as a replacement for '-'.The $value argument may be a scalar or a reference to a list ofscalars. $header->push_header(Accept => 'image/jpeg'); $header->push_header(Accept => [map "image/$_", qw(gif png tiff)]);=item $h->init_header( $field => $value )Set the specified header to the given value, but only if no previousvalue for that field is set.The header field name ($field) is not case sensitive and '_'can be used as a replacement for '-'.The $value argument may be a scalar or a reference to a list ofscalars.=item $h->remove_header( $field, ... )This function removes the header fields with the specified names.The header field names ($field) are not case sensitive and '_'can be used as a replacement for '-'.The return value is the values of the fields removed.  In scalarcontext the number of fields removed is returned.Note that if you pass in multiple field names then it is generally notpossible to tell which of the returned values belonged to which field.=item $h->remove_content_headersThis will remove all the header fields used to describe the content ofa message.  All header field names prefixed with C<Content-> fallsinto this category, as well as C<Allow>, C<Expires> andC<Last-Modified>.  RFC 2616 denote these fields as I<Entity HeaderFields>.The return value is a new C<HTTP::Headers> object that contains theremoved headers only.=item $h->clearThis will remove all header fields.=item $h->header_field_namesReturns the list of distinct names for the fields present in theheader.  The field names have case as suggested by HTTP spec, and thenames are returned in the recommended "Good Practice" order.In scalar context return the number of distinct field names.=item $h->scan( \&process_header_field )Apply a subroutine to each header field in turn.  The callback routineis called with two parameters; the name of the field and a singlevalue (a string).  If a header field is multi-valued, then theroutine is called once for each value.  The field name passed to thecallback routine has case as suggested by HTTP spec, and the headerswill be visited in the recommended "Good Practice" order.Any return values of the callback routine are ignored.  The loop canbe broken by raising an exception (C<die>), but the caller of scan()would have to trap the exception itself.=item $h->as_string=item $h->as_string( $eol )Return the header fields as a formatted MIME header.  Since itinternally uses the C<scan> method to build the string, the resultwill use case as suggested by HTTP spec, and it will followrecommended "Good Practice" of ordering the header fields.  Long headervalues are not folded.The optional $eol parameter specifies the line ending sequence touse.  The default is "\n".  Embedded "\n" characters in header fieldvalues will be substituted with this line ending sequence.=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.If the given header did not exist then C<undef> is 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_sinceThese header fields are used to make a request conditional.  If the requestedresource has (or 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 (my $last_mod = $h->last_modified) {      if ($last_mod < 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.  If there is no such header field, then the emptystring is returned.  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 some kind of Norwegian and "en-US" for English theway it is written in the US.=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('King Kong <king@kong.com>');I<This header is no longer part of the HTTP standard.>=item $h->refererUsed to specify the address (URI) of the document from which therequested resource address was obtained.The "Free On-line Dictionary of Computing" as this to say about theword I<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)By popular demand C<referrer> exists as an alias for this method so youcan avoid this misspelling in your programs and still send the rightthing on the wire.When setting the referrer, this method removes the fragment from thegiven URI if it is present, as mandated by RFC2616.  Note thatthe removal does I<not> happen automatically if using the header(),push_header() or init_header() methods to set the referrer.=item $h->www_authenticateThis header must be included as part of a C<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 C<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 NON-CANONICALIZED FIELD NAMESThe header field name spelling is normally canonicalized including the'_' to '-' translation.  There are some application where this is notappropriate.  Prefixing field names with ':' allow you to force aspecific spelling.  For example if you really want a header field nameto show up as C<foo_bar> instead of "Foo-Bar", you might set it likethis:  $h->header(":foo_bar" => 1);These field names are returned with the ':' intact for$h->header_field_names and the $h->scan callback, but the colons donot show in $h->as_string.=head1 COPYRIGHTCopyright 1995-2005 Gisle Aas.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.

⌨️ 快捷键说明

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