From 57d69a4016b981268198cf744741335a9b1fbb23 Mon Sep 17 00:00:00 2001 From: Chris 'BinGOs' Williams Date: Wed, 30 Jul 2014 09:12:58 +0100 Subject: [PATCH] Update HTTP-Tiny to CPAN version 0.047 [DELTA] 0.047 2014-07-29 14:09:05-04:00 America/New_York [CHANGED] - Updated Mozilla::CA module recommendation version to 20130114 [FIXED] - Fixed t/00-report-prereqs.t when CPAN::Meta is not installed 0.046 2014-07-21 10:32:32-04:00 America/New_York [FIXED] - Empty header fields are now allowed; headers with the 'undef' value will be rendered as an empty header. [DOCUMENTED] - Updated HTTP/1.1 spec description from RFC 2616 to RFC 7230-7235 0.045 2014-07-19 23:17:28-04:00 America/New_York (TRIAL RELEASE) [FIXED] - Fixed t/002_croakage.t for various operating systems. --- Porting/Maintainers.pl | 3 +- cpan/HTTP-Tiny/lib/HTTP/Tiny.pm | 658 ++++++++++++++++++++-------------------- cpan/HTTP-Tiny/t/002_croakage.t | 12 + cpan/HTTP-Tiny/t/020_headers.t | 9 + cpan/HTTP-Tiny/t/140_proxy.t | 14 + 5 files changed, 367 insertions(+), 329 deletions(-) diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index b6cbbc3..bffd16e 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -577,10 +577,11 @@ use File::Glob qw(:case); }, 'HTTP::Tiny' => { - 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.043.tar.gz', + 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.047.tar.gz', 'FILES' => q[cpan/HTTP-Tiny], 'EXCLUDED' => [ 't/00-report-prereqs.t', + 't/00-report-prereqs.dd', 't/200_live.t', 't/200_live_local_ip.t', 't/210_live_ssl.t', diff --git a/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm b/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm index e348753..06c0961 100644 --- a/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm +++ b/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm @@ -3,60 +3,63 @@ package HTTP::Tiny; use strict; use warnings; # ABSTRACT: A small, simple, correct HTTP/1.1 client -our $VERSION = '0.043'; # VERSION +our $VERSION = '0.047'; # VERSION use Carp (); -# =method new -# -# $http = HTTP::Tiny->new( %attributes ); -# -# This constructor returns a new HTTP::Tiny object. Valid attributes include: -# -# =for :list -# * C -# A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C ends in a space character, the default user-agent string is appended. -# * C -# An instance of L or equivalent class that supports the C and C methods -# * C -# A hashref of default headers to apply to requests -# * C -# The local IP address to bind to -# * C -# Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1) -# * C -# Maximum number of redirects allowed (defaults to 5) -# * C -# Maximum response size (only when not using a data callback). If defined, responses larger than this will return an exception. -# * C -# URL of a proxy server to use for HTTP connections (default is C<$ENV{http_proxy}> if set) -# * C -# URL of a proxy server to use for HTTPS connections (default is C<$ENV{https_proxy}> if set) -# * C -# URL of a generic proxy server for both HTTP and HTTPS connections (default is C<$ENV{all_proxy}> if set) -# * C -# List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}>) -# * C -# Request timeout in seconds (default is 60) -# * C -# A boolean that indicates whether to validate the SSL certificate of an C -# connection (default is false) -# * C -# A hashref of C options to pass through to L -# -# Exceptions from C, C or other errors will result in a -# pseudo-HTTP status code of 599 and a reason of "Internal Exception". The -# content field in the response will contain the text of the exception. -# -# The C parameter enables a persistent connection, but only to a -# single destination scheme, host and port. Also, if any connection-relevant -# attributes are modified, a persistent connection will be dropped. If you want -# persistent connections across multiple destinations, use multiple HTTP::Tiny -# objects. -# -# See L for more on the C and C attributes. -# -# =cut +#pod =method new +#pod +#pod $http = HTTP::Tiny->new( %attributes ); +#pod +#pod This constructor returns a new HTTP::Tiny object. Valid attributes include: +#pod +#pod =for :list +#pod * C — +#pod A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C — ends in a space character, the default user-agent string is appended. +#pod * C — +#pod An instance of L — or equivalent class that supports the C and C methods +#pod * C — +#pod A hashref of default headers to apply to requests +#pod * C — +#pod The local IP address to bind to +#pod * C — +#pod Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1) +#pod * C — +#pod Maximum number of redirects allowed (defaults to 5) +#pod * C — +#pod Maximum response size (only when not using a data callback). If defined, responses larger than this will return an exception. +#pod * C — +#pod URL of a proxy server to use for HTTP connections (default is C<$ENV{http_proxy}> — if set) +#pod * C — +#pod URL of a proxy server to use for HTTPS connections (default is C<$ENV{https_proxy}> — if set) +#pod * C — +#pod URL of a generic proxy server for both HTTP and HTTPS connections (default is C<$ENV{all_proxy}> — if set) +#pod * C — +#pod List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}> —) +#pod * C — +#pod Request timeout in seconds (default is 60) +#pod * C — +#pod A boolean that indicates whether to validate the SSL certificate of an C — +#pod connection (default is false) +#pod * C — +#pod A hashref of C — options to pass through to L +#pod +#pod Passing an explicit C for C, C or C will +#pod prevent getting the corresponding proxies from the environment. +#pod +#pod Exceptions from C, C or other errors will result in a +#pod pseudo-HTTP status code of 599 and a reason of "Internal Exception". The +#pod content field in the response will contain the text of the exception. +#pod +#pod The C parameter enables a persistent connection, but only to a +#pod single destination scheme, host and port. Also, if any connection-relevant +#pod attributes are modified, a persistent connection will be dropped. If you want +#pod persistent connections across multiple destinations, use multiple HTTP::Tiny +#pod objects. +#pod +#pod See L for more on the C and C attributes. +#pod +#pod =cut my @attributes; BEGIN { @@ -120,36 +123,45 @@ sub new { sub _set_proxies { my ($self) = @_; - if (! $self->{proxy} ) { + # get proxies from %ENV only if not provided; explicit undef will disable + # getting proxies from the environment + + # generic proxy + if (! exists $self->{proxy} ) { $self->{proxy} = $ENV{all_proxy} || $ENV{ALL_PROXY}; - if ( defined $self->{proxy} ) { - $self->_split_proxy( 'generic proxy' => $self->{proxy} ); # validate - } - else { - delete $self->{proxy}; - } } - if (! $self->{http_proxy} ) { + if ( defined $self->{proxy} ) { + $self->_split_proxy( 'generic proxy' => $self->{proxy} ); # validate + } + else { + delete $self->{proxy}; + } + + # http proxy + if (! exists $self->{http_proxy} ) { $self->{http_proxy} = $ENV{http_proxy} || $self->{proxy}; - if ( defined $self->{http_proxy} ) { - $self->_split_proxy( http_proxy => $self->{http_proxy} ); # validate - $self->{_has_proxy}{http} = 1; - } - else { - delete $self->{http_proxy}; - } } - if (! $self->{https_proxy} ) { + if ( defined $self->{http_proxy} ) { + $self->_split_proxy( http_proxy => $self->{http_proxy} ); # validate + $self->{_has_proxy}{http} = 1; + } + else { + delete $self->{http_proxy}; + } + + # https proxy + if (! exists $self->{https_proxy} ) { $self->{https_proxy} = $ENV{https_proxy} || $ENV{HTTPS_PROXY} || $self->{proxy}; - if ( $self->{https_proxy} ) { - $self->_split_proxy( https_proxy => $self->{https_proxy} ); # validate - $self->{_has_proxy}{https} = 1; - } - else { - delete $self->{https_proxy}; - } + } + + if ( $self->{https_proxy} ) { + $self->_split_proxy( https_proxy => $self->{https_proxy} ); # validate + $self->{_has_proxy}{https} = 1; + } + else { + delete $self->{https_proxy}; } # Split no_proxy to array reference if not provided as such @@ -161,19 +173,19 @@ sub _set_proxies { return; } -# =method get|head|put|post|delete -# -# $response = $http->get($url); -# $response = $http->get($url, \%options); -# $response = $http->head($url); -# -# These methods are shorthand for calling C for the given method. The -# URL must have unsafe characters escaped and international domain names encoded. -# See C for valid options and a description of the response. -# -# The C field of the response will be true if the status code is 2XX. -# -# =cut +#pod =method get|head|put|post|delete +#pod +#pod $response = $http->get($url); +#pod $response = $http->get($url, \%options); +#pod $response = $http->head($url); +#pod +#pod These methods are shorthand for calling C for the given method. The +#pod URL must have unsafe characters escaped and international domain names encoded. +#pod See C for valid options and a description of the response. +#pod +#pod The C field of the response will be true if the status code is 2XX. +#pod +#pod =cut for my $sub_name ( qw/get head put post delete/ ) { my $req_method = uc $sub_name; @@ -188,25 +200,25 @@ for my $sub_name ( qw/get head put post delete/ ) { HERE } -# =method post_form -# -# $response = $http->post_form($url, $form_data); -# $response = $http->post_form($url, $form_data, \%options); -# -# This method executes a C request and sends the key/value pairs from a -# form data hash or array reference to the given URL with a C of -# C. If data is provided as an array -# reference, the order is preserved; if provided as a hash reference, the terms -# are sorted on key and value for consistency. See documentation for the -# C method for details on the encoding. -# -# The URL must have unsafe characters escaped and international domain names -# encoded. See C for valid options and a description of the response. -# Any C header or content in the options hashref will be ignored. -# -# The C field of the response will be true if the status code is 2XX. -# -# =cut +#pod =method post_form +#pod +#pod $response = $http->post_form($url, $form_data); +#pod $response = $http->post_form($url, $form_data, \%options); +#pod +#pod This method executes a C request and sends the key/value pairs from a +#pod form data hash or array reference to the given URL with a C of +#pod C. If data is provided as an array +#pod reference, the order is preserved; if provided as a hash reference, the terms +#pod are sorted on key and value for consistency. See documentation for the +#pod C method for details on the encoding. +#pod +#pod The URL must have unsafe characters escaped and international domain names +#pod encoded. See C for valid options and a description of the response. +#pod Any C header or content in the options hashref will be ignored. +#pod +#pod The C field of the response will be true if the status code is 2XX. +#pod +#pod =cut sub post_form { my ($self, $url, $data, $args) = @_; @@ -230,28 +242,28 @@ sub post_form { ); } -# =method mirror -# -# $response = $http->mirror($url, $file, \%options) -# if ( $response->{success} ) { -# print "$file is up to date\n"; -# } -# -# Executes a C request for the URL and saves the response body to the file -# name provided. The URL must have unsafe characters escaped and international -# domain names encoded. If the file already exists, the request will include an -# C header with the modification timestamp of the file. You -# may specify a different C header yourself in the C<< -# $options->{headers} >> hash. -# -# The C field of the response will be true if the status code is 2XX -# or if the status code is 304 (unmodified). -# -# If the file was modified and the server response includes a properly -# formatted C header, the file modification time will -# be updated accordingly. -# -# =cut +#pod =method mirror +#pod +#pod $response = $http->mirror($url, $file, \%options) +#pod if ( $response->{success} ) { +#pod print "$file is up to date\n"; +#pod } +#pod +#pod Executes a C request for the URL and saves the response body to the file +#pod name provided. The URL must have unsafe characters escaped and international +#pod domain names encoded. If the file already exists, the request will include an +#pod C header with the modification timestamp of the file. You +#pod may specify a different C header yourself in the C<< +#pod $options->{headers} >> hash. +#pod +#pod The C field of the response will be true if the status code is 2XX +#pod or if the status code is 304 (unmodified). +#pod +#pod If the file was modified and the server response includes a properly +#pod formatted C header, the file modification time will +#pod be updated accordingly. +#pod +#pod =cut sub mirror { my ($self, $url, $file, $args) = @_; @@ -284,86 +296,90 @@ sub mirror { return $response; } -# =method request -# -# $response = $http->request($method, $url); -# $response = $http->request($method, $url, \%options); -# -# Executes an HTTP request of the given method type ('GET', 'HEAD', 'POST', -# 'PUT', etc.) on the given URL. The URL must have unsafe characters escaped and -# international domain names encoded. -# -# If the URL includes a "user:password" stanza, they will be used for Basic-style -# authorization headers. (Authorization headers will not be included in a -# redirected request.) For example: -# -# $http->request('GET', 'http://Aladdin:open sesame@example.com/'); -# -# If the "user:password" stanza contains reserved characters, they must -# be percent-escaped: -# -# $http->request('GET', 'http://john%40example.com:password@example.com/'); -# -# A hashref of options may be appended to modify the request. -# -# Valid options are: -# -# =for :list -# * C -# A hashref containing headers to include with the request. If the value for -# a header is an array reference, the header will be output multiple times with -# each value in the array. These headers over-write any default headers. -# * C -# A scalar to include as the body of the request OR a code reference -# that will be called iteratively to produce the body of the request -# * C -# A code reference that will be called if it exists to provide a hashref -# of trailing headers (only used with chunked transfer-encoding) -# * C -# A code reference that will be called for each chunks of the response -# body received. -# -# If the C option is a code reference, it will be called iteratively -# to provide the content body of the request. It should return the empty -# string or undef when the iterator is exhausted. -# -# If the C option is the empty string, no C or -# C headers will be generated. -# -# If the C option is provided, it will be called iteratively until -# the entire response body is received. The first argument will be a string -# containing a chunk of the response body, the second argument will be the -# in-progress response hash reference, as described below. (This allows -# customizing the action of the callback based on the C or C -# received prior to the content body.) -# -# The C method returns a hashref containing the response. The hashref -# will have the following keys: -# -# =for :list -# * C -# Boolean indicating whether the operation returned a 2XX status code -# * C -# URL that provided the response. This is the URL of the request unless -# there were redirections, in which case it is the last URL queried -# in a redirection chain -# * C -# The HTTP status code of the response -# * C -# The response phrase returned by the server -# * C -# The body of the response. If the response does not have any content -# or if a data callback is provided to consume the response body, -# this will be the empty string -# * C -# A hashref of header fields. All header field names will be normalized -# to be lower case. If a header is repeated, the value will be an arrayref; -# it will otherwise be a scalar string containing the value -# -# On an exception during the execution of the request, the C field will -# contain 599, and the C field will contain the text of the exception. -# -# =cut +#pod =method request +#pod +#pod $response = $http->request($method, $url); +#pod $response = $http->request($method, $url, \%options); +#pod +#pod Executes an HTTP request of the given method type ('GET', 'HEAD', 'POST', +#pod 'PUT', etc.) on the given URL. The URL must have unsafe characters escaped and +#pod international domain names encoded. +#pod +#pod If the URL includes a "user:password" stanza, they will be used for Basic-style +#pod authorization headers. (Authorization headers will not be included in a +#pod redirected request.) For example: +#pod +#pod $http->request('GET', 'http://Aladdin:open sesame@example.com/'); +#pod +#pod If the "user:password" stanza contains reserved characters, they must +#pod be percent-escaped: +#pod +#pod $http->request('GET', 'http://john%40example.com:password@example.com/'); +#pod +#pod A hashref of options may be appended to modify the request. +#pod +#pod Valid options are: +#pod +#pod =for :list +#pod * C — +#pod A hashref containing headers to include with the request. If the value for +#pod a header is an array reference, the header will be output multiple times with +#pod each value in the array. These headers over-write any default headers. +#pod * C — +#pod A scalar to include as the body of the request OR a code reference +#pod that will be called iteratively to produce the body of the request +#pod * C — +#pod A code reference that will be called if it exists to provide a hashref +#pod of trailing headers (only used with chunked transfer-encoding) +#pod * C — +#pod A code reference that will be called for each chunks of the response +#pod body received. +#pod +#pod The C header is generated from the URL in accordance with RFC 2616. It +#pod is a fatal error to specify C in the C option. Other headers +#pod may be ignored or overwritten if necessary for transport compliance. +#pod +#pod If the C option is a code reference, it will be called iteratively +#pod to provide the content body of the request. It should return the empty +#pod string or undef when the iterator is exhausted. +#pod +#pod If the C option is the empty string, no C or +#pod C headers will be generated. +#pod +#pod If the C option is provided, it will be called iteratively until +#pod the entire response body is received. The first argument will be a string +#pod containing a chunk of the response body, the second argument will be the +#pod in-progress response hash reference, as described below. (This allows +#pod customizing the action of the callback based on the C or C +#pod received prior to the content body.) +#pod +#pod The C method returns a hashref containing the response. The hashref +#pod will have the following keys: +#pod +#pod =for :list +#pod * C — +#pod Boolean indicating whether the operation returned a 2XX status code +#pod * C — +#pod URL that provided the response. This is the URL of the request unless +#pod there were redirections, in which case it is the last URL queried +#pod in a redirection chain +#pod * C — +#pod The HTTP status code of the response +#pod * C — +#pod The response phrase returned by the server +#pod * C — +#pod The body of the response. If the response does not have any content +#pod or if a data callback is provided to consume the response body, +#pod this will be the empty string +#pod * C — +#pod A hashref of header fields. All header field names will be normalized +#pod to be lower case. If a header is repeated, the value will be an arrayref; +#pod it will otherwise be a scalar string containing the value +#pod +#pod On an exception during the execution of the request, the C field will +#pod contain 599, and the C field will contain the text of the exception. +#pod +#pod =cut my %idempotent = map { $_ => 1 } qw/GET HEAD PUT DELETE OPTIONS TRACE/; @@ -404,19 +420,19 @@ sub request { return $response; } -# =method www_form_urlencode -# -# $params = $http->www_form_urlencode( $data ); -# $response = $http->get("http://example.com/query?$params"); -# -# This method converts the key/value pairs from a data hash or array reference -# into a C string. The keys and values from the data -# reference will be UTF-8 encoded and escaped per RFC 3986. If a value is an -# array reference, the key will be repeated with each of the values of the array -# reference. If data is provided as a hash reference, the key/value pairs in the -# resulting string will be sorted by key and value for consistent ordering. -# -# =cut +#pod =method www_form_urlencode +#pod +#pod $params = $http->www_form_urlencode( $data ); +#pod $response = $http->get("http://example.com/query?$params"); +#pod +#pod This method converts the key/value pairs from a data hash or array reference +#pod into a C string. The keys and values from the data +#pod reference will be UTF-8 encoded and escaped per RFC 3986. If a value is an +#pod array reference, the key will be repeated with each of the values of the array +#pod reference. If data is provided as a hash reference, the key/value pairs in the +#pod resulting string will be sorted by key and value for consistent ordering. +#pod +#pod =cut sub www_form_urlencode { my ($self, $data) = @_; @@ -641,6 +657,11 @@ sub _prepare_headers_and_cb { $request->{headers}{lc $k} = $v; } } + + if (exists $request->{headers}{'host'}) { + die(qq/The 'Host' header must not be provided as header option\n/); + } + $request->{headers}{'host'} = $request->{host_port}; $request->{headers}{'user-agent'} ||= $self->{agent}; $request->{headers}{'connection'} = "close" @@ -757,31 +778,27 @@ sub _split_url { my $url = pop; # URI regex adapted from the URI module - my ($scheme, $authority, $path_query) = $url =~ m<\A([^:/?#]+)://([^/?#]*)([^#]*)> + my ($scheme, $host, $path_query) = $url =~ m<\A([^:/?#]+)://([^/?#]*)([^#]*)> or die(qq/Cannot parse URL: '$url'\n/); $scheme = lc $scheme; $path_query = "/$path_query" unless $path_query =~ m<\A/>; - my ($auth,$host); - $authority = (length($authority)) ? $authority : 'localhost'; - if ( $authority =~ /@/ ) { - ($auth,$host) = $authority =~ m/\A([^@]*)@(.*)\z/; # user:pass@host + my $auth = ''; + if ( (my $i = index $host, '@') != -1 ) { + # user:pass@host + $auth = substr $host, 0, $i, ''; # take up to the @ for auth + substr $host, 0, 1, ''; # knock the @ off the host + # userinfo might be percent escaped, so recover real auth info $auth =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; } - else { - $host = $authority; - $auth = ''; - } - $host = lc $host; - my $port = do { - $host =~ s/:([0-9]*)\z// && length $1 - ? $1 - : ($scheme eq 'http' ? 80 : $scheme eq 'https' ? 443 : undef); - }; + my $port = $host =~ s/:(\d*)\z// && length $1 ? $1 + : $scheme eq 'http' ? 80 + : $scheme eq 'https' ? 443 + : undef; - return ($scheme, $host, $port, $path_query, $auth); + return ($scheme, (length $host ? lc $host : "localhost") , $port, $path_query, $auth); } # Date conversions adapted from HTTP::Date @@ -1132,8 +1149,7 @@ sub write_header_lines { $HeaderCase{lc $field_name} = $field_name; } for (ref $v eq 'ARRAY' ? @$v : $v) { - /[^\x0D\x0A]/ - or die(qq/Invalid HTTP header field value ($field_name): / . $Printable->($_). "\n"); + $_ = '' unless defined $_; $buf .= "$field_name: $_\x0D\x0A"; } } @@ -1428,7 +1444,7 @@ HTTP::Tiny - A small, simple, correct HTTP/1.1 client =head1 VERSION -version 0.043 +version 0.047 =head1 SYNOPSIS @@ -1473,91 +1489,65 @@ This constructor returns a new HTTP::Tiny object. Valid attributes include: =item * -C - -A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C ends in a space character, the default user-agent string is appended. +C — A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C — ends in a space character, the default user-agent string is appended. =item * -C - -An instance of L or equivalent class that supports the C and C methods +C — An instance of L — or equivalent class that supports the C and C methods =item * -C - -A hashref of default headers to apply to requests +C — A hashref of default headers to apply to requests =item * -C - -The local IP address to bind to +C — The local IP address to bind to =item * -C - -Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1) +C — Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1) =item * -C - -Maximum number of redirects allowed (defaults to 5) +C — Maximum number of redirects allowed (defaults to 5) =item * -C - -Maximum response size (only when not using a data callback). If defined, responses larger than this will return an exception. +C — Maximum response size (only when not using a data callback). If defined, responses larger than this will return an exception. =item * -C - -URL of a proxy server to use for HTTP connections (default is C<$ENV{http_proxy}> if set) +C — URL of a proxy server to use for HTTP connections (default is C<$ENV{http_proxy}> — if set) =item * -C - -URL of a proxy server to use for HTTPS connections (default is C<$ENV{https_proxy}> if set) +C — URL of a proxy server to use for HTTPS connections (default is C<$ENV{https_proxy}> — if set) =item * -C - -URL of a generic proxy server for both HTTP and HTTPS connections (default is C<$ENV{all_proxy}> if set) +C — URL of a generic proxy server for both HTTP and HTTPS connections (default is C<$ENV{all_proxy}> — if set) =item * -C - -List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}>) +C — List of domain suffixes that should not be proxied. Must be a comma-separated string or an array reference. (default is C<$ENV{no_proxy}> —) =item * -C - -Request timeout in seconds (default is 60) +C — Request timeout in seconds (default is 60) =item * -C - -A boolean that indicates whether to validate the SSL certificate of an C -connection (default is false) +C — A boolean that indicates whether to validate the SSL certificate of an C — connection (default is false) =item * -C - -A hashref of C options to pass through to L +C — A hashref of C — options to pass through to L =back +Passing an explicit C for C, C or C will +prevent getting the corresponding proxies from the environment. + Exceptions from C, C or other errors will result in a pseudo-HTTP status code of 599 and a reason of "Internal Exception". The content field in the response will contain the text of the exception. @@ -1649,35 +1639,26 @@ Valid options are: =item * -C - -A hashref containing headers to include with the request. If the value for -a header is an array reference, the header will be output multiple times with -each value in the array. These headers over-write any default headers. +C — A hashref containing headers to include with the request. If the value for a header is an array reference, the header will be output multiple times with each value in the array. These headers over-write any default headers. =item * -C - -A scalar to include as the body of the request OR a code reference -that will be called iteratively to produce the body of the request +C — A scalar to include as the body of the request OR a code reference that will be called iteratively to produce the body of the request =item * -C - -A code reference that will be called if it exists to provide a hashref -of trailing headers (only used with chunked transfer-encoding) +C — A code reference that will be called if it exists to provide a hashref of trailing headers (only used with chunked transfer-encoding) =item * -C - -A code reference that will be called for each chunks of the response -body received. +C — A code reference that will be called for each chunks of the response body received. =back +The C header is generated from the URL in accordance with RFC 2616. It +is a fatal error to specify C in the C option. Other headers +may be ignored or overwritten if necessary for transport compliance. + If the C option is a code reference, it will be called iteratively to provide the content body of the request. It should return the empty string or undef when the iterator is exhausted. @@ -1699,45 +1680,27 @@ will have the following keys: =item * -C - -Boolean indicating whether the operation returned a 2XX status code +C — Boolean indicating whether the operation returned a 2XX status code =item * -C - -URL that provided the response. This is the URL of the request unless -there were redirections, in which case it is the last URL queried -in a redirection chain +C — URL that provided the response. This is the URL of the request unless there were redirections, in which case it is the last URL queried in a redirection chain =item * -C - -The HTTP status code of the response +C — The HTTP status code of the response =item * -C - -The response phrase returned by the server +C — The response phrase returned by the server =item * -C - -The body of the response. If the response does not have any content -or if a data callback is provided to consume the response body, -this will be the empty string +C — The body of the response. If the response does not have any content or if a data callback is provided to consume the response body, this will be the empty string =item * -C - -A hashref of header fields. All header field names will be normalized -to be lower case. If a header is repeated, the value will be an arrayref; -it will otherwise be a scalar string containing the value +C — A hashref of header fields. All header field names will be normalized to be lower case. If a header is repeated, the value will be an arrayref; it will otherwise be a scalar string containing the value =back @@ -1775,7 +1738,7 @@ verify_SSL Direct C connections are supported only if L 1.56 or greater and L 1.49 or greater are installed. An exception will be -thrown if a new enough versions of these modules not installed or if the SSL +thrown if new enough versions of these modules are not installed or if the SSL encryption fails. An C connection may be made via an C proxy that supports the CONNECT command (i.e. RFC 2817). You may not proxy C via a proxy that itself requires C to communicate. @@ -1895,9 +1858,40 @@ environment variables. =head1 LIMITATIONS HTTP::Tiny is I with the -L. +L: + +=over 4 + +=item * + +"Message Syntax and Routing" [RFC7230] + +=item * + +"Semantics and Content" [RFC7231] + +=item * + +"Conditional Requests" [RFC7232] + +=item * + +"Range Requests" [RFC7233] + +=item * + +"Caching" [RFC7234] + +=item * + +"Authentication" [RFC7235] + +=back + It attempts to meet all "MUST" requirements of the specification, but does not -implement all "SHOULD" requirements. +implement all "SHOULD" requirements. (Note: it was developed against the +earlier RFC 2616 specification and may not yet meet the revised RFC 7230-7235 +spec.) Some particular limitations of note include: @@ -2035,7 +2029,7 @@ Chris Nehren =item * -Chris Weyl +Chris Weyl =item * @@ -2059,6 +2053,10 @@ Edward Zborowski =item * +James Raspass + +=item * + Jess Robinson =item * @@ -2091,6 +2089,10 @@ Syohei YOSHIDA =item * +Sören Kornetzki + +=item * + Tony Cook =back diff --git a/cpan/HTTP-Tiny/t/002_croakage.t b/cpan/HTTP-Tiny/t/002_croakage.t index a243ebc..9e51b5d 100644 --- a/cpan/HTTP-Tiny/t/002_croakage.t +++ b/cpan/HTTP-Tiny/t/002_croakage.t @@ -4,8 +4,12 @@ use strict; use warnings; use Test::More; +use t::Util qw[tmpfile monkey_patch set_socket_source]; + use HTTP::Tiny; +BEGIN { monkey_patch() } + my %usage = ( 'get' => q/Usage: $http->get(URL, [HASHREF])/, 'mirror' => q/Usage: $http->mirror(URL, FILE, [HASHREF])/, @@ -26,7 +30,11 @@ my @cases = ( ['request','GET','http://www.example.com/','extra', 'extra'], ); +my $res_fh = tmpfile(); +my $req_fh = tmpfile(); + my $http = HTTP::Tiny->new; +set_socket_source($req_fh, $res_fh); for my $c ( @cases ) { my ($method, @args) = @$c; @@ -35,5 +43,9 @@ for my $c ( @cases ) { like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) ); } +my $res = eval{ $http->get("http://www.example.com/", { headers => { host => "www.example2.com" } } ) }; +is( $res->{status}, 599, "Providing a Host header errors with 599" ); +like( $res->{content}, qr/'Host' header/, "Providing a Host header gives right error message" ); + done_testing; diff --git a/cpan/HTTP-Tiny/t/020_headers.t b/cpan/HTTP-Tiny/t/020_headers.t index 970faa6..c10e075 100644 --- a/cpan/HTTP-Tiny/t/020_headers.t +++ b/cpan/HTTP-Tiny/t/020_headers.t @@ -49,3 +49,12 @@ use HTTP::Tiny; is_deeply($handle->read_header_lines, $headers, "roundtrip header lines"); } +{ + my $fh = tmpfile(); + my $handle = HTTP::Tiny::Handle->new(fh => $fh); + my $headers = { foo => ['Foo', 'Baz'], bar => 'Bar', baz => '' }; + $handle->write_header_lines($headers); + rewind($fh); + is_deeply($handle->read_header_lines, $headers, "roundtrip header lines"); +} + diff --git a/cpan/HTTP-Tiny/t/140_proxy.t b/cpan/HTTP-Tiny/t/140_proxy.t index 401f8ae..6ecc6a5 100644 --- a/cpan/HTTP-Tiny/t/140_proxy.t +++ b/cpan/HTTP-Tiny/t/140_proxy.t @@ -31,5 +31,19 @@ for my $proxy ("http://localhost:8080/", "http://localhost:8080"){ like($@, qr{http_proxy URL must be in format http\[s\]://\[auth\@\]:/}); } +# Explicitly disable proxy +{ + local $ENV{all_proxy} = "http://localhost:8080"; + local $ENV{http_proxy} = "http://localhost:8080"; + local $ENV{https_proxy} = "http://localhost:8080"; + my $c = HTTP::Tiny->new( + proxy => undef, + http_proxy => undef, + https_proxy => undef, + ); + ok(!defined $c->proxy, "proxy => undef disables ENV proxy"); + ok(!defined $c->http_proxy, "http_proxy => undef disables ENV proxy"); + ok(!defined $c->https_proxy, "https_proxy => undef disables ENV proxy"); +} done_testing(); -- 1.8.3.1