Commit 23a3bbd4 authored by Nick Morrott's avatar Nick Morrott

Imported Upstream version 0.058

parent a45123eb
Release notes for HTTP-Tiny
0.058 2016-05-03 11:29:57-04:00 America/New_York
- No changes from 0.057
0.057 2016-04-18 10:17:00-04:00 America/New_York (TRIAL RELEASE)
[ADDED]
- Added support for the SSL_CERT_FILE environment variable.
- Added 'peer' attribute to force a connection to a particular
server.
- Added 'connected' method to allow introspection of persistent
connections.
- An array reference of redirection result hash references is included
in the final response hash reference (but only if redirects occur).
[CHANGED]
- Because folded headers are obsoleted in the revised RFCs, if CRLF is
found in header values followed by one or more spaces, they are all
replaced by a single space.
[FIXED]
- Per the RFC, control headers are now sent first before other headers
(which are sent in arbitrary order).
- Only well-known headers have their case canonicalized; all other
headers are sent in the case provided by the user.
- The 'keep_alive' option now also sets the SO_KEEPALIVE option
on the underlying socket to help with long-lived, idle connections.
- Request header field values are now validated against the RFC rules
(i.e. empty or else space-or-tab separated tokens of printable
characters).
0.056 2015-05-19 06:00:40-04:00 America/New_York
- No changes from 0.055
......
This software is copyright (c) 2015 by Christian Hansen.
This software is copyright (c) 2016 by Christian Hansen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
......@@ -12,7 +12,7 @@ b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2015 by Christian Hansen.
This software is Copyright (c) 2016 by Christian Hansen.
This is free software, licensed under:
......@@ -272,7 +272,7 @@ That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2015 by Christian Hansen.
This software is Copyright (c) 2016 by Christian Hansen.
This is free software, licensed under:
......
# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.036.
# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.003.
CONTRIBUTING.mkdn
Changes
LICENSE
......@@ -46,6 +46,7 @@ corpus/get-18.txt
corpus/get-19.txt
corpus/get-20.txt
corpus/get-21.txt
corpus/get-22.txt
corpus/head-01.txt
corpus/keepalive-01.txt
corpus/keepalive-02.txt
......@@ -116,10 +117,10 @@ t/SimpleCookieJar.pm
t/Util.pm
xt/author/00-compile.t
xt/author/critic.t
xt/author/pod-coverage.t
xt/author/pod-spell.t
xt/author/pod-syntax.t
xt/author/test-version.t
xt/release/distmeta.t
xt/release/minimum-version.t
xt/release/pod-coverage.t
xt/release/pod-syntax.t
xt/release/portability.t
xt/release/test-version.t
......@@ -5,7 +5,7 @@
"David Golden <dagolden@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 5.036, CPAN::Meta::Converter version 2.150002",
"generated_by" : "Dist::Zilla version 6.003, CPAN::Meta::Converter version 2.150001",
"license" : [
"perl_5"
],
......@@ -16,10 +16,10 @@
"name" : "HTTP-Tiny",
"no_index" : {
"directory" : [
"t",
"xt",
"corpus",
"examples",
"corpus"
"t",
"xt"
],
"package" : [
"DB"
......@@ -30,6 +30,9 @@
"requires" : {
"ExtUtils::MakeMaker" : "6.17",
"perl" : "5.006"
},
"suggests" : {
"JSON::PP" : "2.27300"
}
},
"develop" : {
......@@ -38,26 +41,31 @@
"Dist::Zilla::Plugin::Prereqs" : "0",
"Dist::Zilla::Plugin::RemovePrereqs" : "0",
"Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072",
"English" : "0",
"File::Spec" : "0",
"File::Temp" : "0",
"IO::Handle" : "0",
"IPC::Open3" : "0",
"Perl::Critic::Policy::Lax::ProhibitStringyEval::ExceptForRequire" : "0",
"Pod::Coverage::TrustPod" : "0",
"Pod::Wordlist" : "0",
"Software::License::Perl_5" : "0",
"Test::CPAN::Meta" : "0",
"Test::More" : "0",
"Test::Pod" : "1.41",
"Test::Pod::Coverage" : "1.08",
"Test::Spelling" : "0.12",
"Test::Version" : "1"
"Test::Version" : "1",
"blib" : "1.01",
"perl" : "5.006"
}
},
"runtime" : {
"recommends" : {
"HTTP::CookieJar" : "0.001",
"IO::Socket::IP" : "0.25",
"IO::Socket::IP" : "0.32",
"IO::Socket::SSL" : "1.42",
"Mozilla::CA" : "20130114",
"Mozilla::CA" : "20160104",
"Net::SSLeay" : "1.49"
},
"requires" : {
......@@ -65,6 +73,7 @@
"Fcntl" : "0",
"IO::Socket" : "0",
"MIME::Base64" : "0",
"Socket" : "0",
"Time::Local" : "0",
"bytes" : "0",
"perl" : "5.006",
......@@ -99,7 +108,7 @@
"provides" : {
"HTTP::Tiny" : {
"file" : "lib/HTTP/Tiny.pm",
"version" : "0.056"
"version" : "0.058"
}
},
"release_status" : "stable",
......@@ -114,16 +123,19 @@
"web" : "https://github.com/chansen/p5-http-tiny"
}
},
"version" : "0.056",
"version" : "0.058",
"x_authority" : "cpan:DAGOLDEN",
"x_contributors" : [
"Alan Gardner <gardner@pythian.com>",
"Alessandro Ghedini <al3xbio@gmail.com>",
"A. Sinan Unur <nanis@cpan.org>",
"Brad Gilbert <bgills@cpan.org>",
"brian m. carlson <sandals@crustytoothpaste.net>",
"Chris Nehren <apeiron@cpan.org>",
"Chris Weyl <cweyl@alumni.drew.edu>",
"Claes Jakobsson <claes@surfar.nu>",
"Clinton Gormley <clint@traveljury.com>",
"David Golden <xdg@xdg.me>",
"Dean Pearce <pearce@pythian.com>",
"Edward Zborowski <ed@rubensteintech.com>",
"James Raspass <jraspass@gmail.com>",
......@@ -134,9 +146,10 @@
"Martin-Louis Bright <mlbright@gmail.com>",
"Mike Doherty <doherty@cpan.org>",
"Olaf Alders <olaf@wundersolutions.com>",
"Olivier Mengué <dolmen@cpan.org>",
"Petr Písař <ppisar@redhat.com>",
"Sören Kornetzki <soeren.kornetzki@delti.com>",
"Olivier Mengu\u00e9 <dolmen@cpan.org>",
"Petr P\u00edsa\u0159 <ppisar@redhat.com>",
"SkyMarshal <skymarshal1729@gmail.com>",
"S\u00f6ren Kornetzki <soeren.kornetzki@delti.com>",
"Syohei YOSHIDA <syohex@gmail.com>",
"Tatsuhiko Miyagawa <miyagawa@bulknews.net>",
"Tom Hukins <tom@eborcom.com>",
......
......@@ -21,7 +21,7 @@ configure_requires:
ExtUtils::MakeMaker: '6.17'
perl: '5.006'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.036, CPAN::Meta::Converter version 2.150002'
generated_by: 'Dist::Zilla version 6.003, CPAN::Meta::Converter version 2.150001'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -29,27 +29,28 @@ meta-spec:
name: HTTP-Tiny
no_index:
directory:
- corpus
- examples
- t
- xt
- examples
- corpus
package:
- DB
provides:
HTTP::Tiny:
file: lib/HTTP/Tiny.pm
version: '0.056'
version: '0.058'
recommends:
HTTP::CookieJar: '0.001'
IO::Socket::IP: '0.25'
IO::Socket::IP: '0.32'
IO::Socket::SSL: '1.42'
Mozilla::CA: '20130114'
Mozilla::CA: '20160104'
Net::SSLeay: '1.49'
requires:
Carp: '0'
Fcntl: '0'
IO::Socket: '0'
MIME::Base64: '0'
Socket: '0'
Time::Local: '0'
bytes: '0'
perl: '5.006'
......@@ -59,16 +60,19 @@ resources:
bugtracker: https://github.com/chansen/p5-http-tiny/issues
homepage: https://github.com/chansen/p5-http-tiny
repository: https://github.com/chansen/p5-http-tiny.git
version: '0.056'
version: '0.058'
x_authority: cpan:DAGOLDEN
x_contributors:
- 'Alan Gardner <gardner@pythian.com>'
- 'Alessandro Ghedini <al3xbio@gmail.com>'
- 'A. Sinan Unur <nanis@cpan.org>'
- 'Brad Gilbert <bgills@cpan.org>'
- 'brian m. carlson <sandals@crustytoothpaste.net>'
- 'Chris Nehren <apeiron@cpan.org>'
- 'Chris Weyl <cweyl@alumni.drew.edu>'
- 'Claes Jakobsson <claes@surfar.nu>'
- 'Clinton Gormley <clint@traveljury.com>'
- 'David Golden <xdg@xdg.me>'
- 'Dean Pearce <pearce@pythian.com>'
- 'Edward Zborowski <ed@rubensteintech.com>'
- 'James Raspass <jraspass@gmail.com>'
......@@ -81,6 +85,7 @@ x_contributors:
- 'Olaf Alders <olaf@wundersolutions.com>'
- 'Olivier Mengué <dolmen@cpan.org>'
- 'Petr Písař <ppisar@redhat.com>'
- 'SkyMarshal <skymarshal1729@gmail.com>'
- 'Sören Kornetzki <soeren.kornetzki@delti.com>'
- 'Syohei YOSHIDA <syohex@gmail.com>'
- 'Tatsuhiko Miyagawa <miyagawa@bulknews.net>'
......
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.036.
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.003.
use strict;
use warnings;
......@@ -13,7 +13,6 @@ my %WriteMakefileArgs = (
"ExtUtils::MakeMaker" => "6.17"
},
"DISTNAME" => "HTTP-Tiny",
"EXE_FILES" => [],
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.006",
"NAME" => "HTTP::Tiny",
......@@ -22,6 +21,7 @@ my %WriteMakefileArgs = (
"Fcntl" => 0,
"IO::Socket" => 0,
"MIME::Base64" => 0,
"Socket" => 0,
"Time::Local" => 0,
"bytes" => 0,
"strict" => 0,
......@@ -41,7 +41,7 @@ my %WriteMakefileArgs = (
"Test::More" => "0.96",
"open" => 0
},
"VERSION" => "0.056",
"VERSION" => "0.058",
"test" => {
"TESTS" => "t/*.t"
}
......@@ -52,7 +52,7 @@ my %FallbackPrereqs = (
"Carp" => 0,
"Data::Dumper" => 0,
"Exporter" => 0,
"ExtUtils::MakeMaker" => "6.17",
"ExtUtils::MakeMaker" => 0,
"Fcntl" => 0,
"File::Basename" => 0,
"File::Spec" => 0,
......@@ -63,6 +63,7 @@ my %FallbackPrereqs = (
"IO::Socket::INET" => 0,
"IPC::Cmd" => 0,
"MIME::Base64" => 0,
"Socket" => 0,
"Test::More" => "0.96",
"Time::Local" => 0,
"bytes" => 0,
......
......@@ -2,7 +2,7 @@ NAME
HTTP::Tiny - A small, simple, correct HTTP/1.1 client
VERSION
version 0.056
version 0.058
SYNOPSIS
use HTTP::Tiny;
......@@ -75,7 +75,9 @@ METHODS
Must be a comma-separated string or an array reference. (default is
$ENV{no_proxy} —)
* "timeout" — Request timeout in seconds (default is 60)
* "timeout" — Request timeout in seconds (default is 60) If a socket
open, read or write takes longer than the timeout, an exception is
thrown.
* "verify_SSL" — A boolean that indicates whether to validate the SSL
certificate of an "https" — connection (default is false)
......@@ -192,6 +194,12 @@ METHODS
* "data_callback" — A code reference that will be called for each
chunks of the response body received.
* "peer" — Override host resolution and force all connections to go
only to a specific peer address, regardless of the URL of the
request. This will include any redirections! This options should be
used with extreme caution (e.g. debugging or very special
circumstances).
The "Host" header is generated from the URL in accordance with RFC 2616.
It is a fatal error to specify "Host" in the "headers" option. Other
headers may be ignored or overwritten if necessary for transport
......@@ -234,6 +242,10 @@ METHODS
will be an arrayref; it will otherwise be a scalar string containing
the value
* "redirects" If this field exists, it is an arrayref of response hash
references from redirects in the same order that redirections
occurred. If it does not exist, then no redirections occurred.
On an exception during the execution of the request, the "status" field
will contain 599, and the "content" field will contain the text of the
exception.
......@@ -265,6 +277,20 @@ METHODS
list context, returns the boolean and a (possibly multi-line) string of
errors indicating why SSL isn't available.
connected
$host = $http->connected;
($host, $port) = $http->connected;
Indicates if a connection to a peer is being kept alive, per the
"keep_alive" option.
In scalar context, returns the peer host and port, joined with a colon,
or "undef" (if no peer is connected). In list context, returns the peer
host and port or an empty list (if no peer is connected).
Note: This method cannot reliably be used to discover whether the remote
host has closed its end of the socket.
SSL SUPPORT
Direct "https" connections are supported only if IO::Socket::SSL 1.56 or
greater and Net::SSLeay 1.49 or greater are installed. An exception will
......@@ -305,11 +331,16 @@ SSL SUPPORT
concerned about security, you should enable this option.
Certificate verification requires a file containing trusted CA
certificates. If the Mozilla::CA module is installed, HTTP::Tiny will
use the CA file included with it as a source of trusted CA's. (This
means you trust Mozilla, the author of Mozilla::CA, the CPAN mirror
where you got Mozilla::CA, the toolchain used to install it, and your
operating system security, right?)
certificates.
If the environment variable "SSL_CERT_FILE" is present, HTTP::Tiny will
try to find a CA certificate file in that location.
If the Mozilla::CA module is installed, HTTP::Tiny will use the CA file
included with it as a source of trusted CA's. (This means you trust
Mozilla, the author of Mozilla::CA, the CPAN mirror where you got
Mozilla::CA, the toolchain used to install it, and your operating system
security, right?)
If that module is not available, then HTTP::Tiny will search several
system-specific default locations for a CA certificate file:
......@@ -415,6 +446,11 @@ LIMITATIONS
* There is no support for a Request-URI of '*' for the 'OPTIONS'
request.
* Headers mentioned in the RFCs and some other, well-known headers are
generated with their canonical case. Other headers are sent in the
case provided by the user. Except for control headers (which are
sent first), headers are sent in arbitrary order.
Despite the limitations listed above, HTTP::Tiny is considered
feature-complete. New feature requests should be directed to
HTTP::Tiny::UA.
......@@ -463,8 +499,12 @@ CONTRIBUTORS
* Alessandro Ghedini <al3xbio@gmail.com>
* A. Sinan Unur <nanis@cpan.org>
* Brad Gilbert <bgills@cpan.org>
* brian m. carlson <sandals@crustytoothpaste.net>
* Chris Nehren <apeiron@cpan.org>
* Chris Weyl <cweyl@alumni.drew.edu>
......@@ -473,6 +513,8 @@ CONTRIBUTORS
* Clinton Gormley <clint@traveljury.com>
* David Golden <xdg@xdg.me>
* Dean Pearce <pearce@pythian.com>
* Edward Zborowski <ed@rubensteintech.com>
......@@ -497,6 +539,8 @@ CONTRIBUTORS
* Petr Písař <ppisar@redhat.com>
* SkyMarshal <skymarshal1729@gmail.com>
* Sören Kornetzki <soeren.kornetzki@delti.com>
* Syohei YOSHIDA <syohex@gmail.com>
......@@ -508,7 +552,7 @@ CONTRIBUTORS
* Tony Cook <tony@develop-help.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Christian Hansen.
This software is copyright (c) 2016 by Christian Hansen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
......
......@@ -5,13 +5,17 @@ expected
headers
Accept: */*
X-Custom: This is a custom header
x-lower: This is a lower-case custom header
authorization: fake auth data
----------
GET /index.html HTTP/1.1
Host: example.com
Accept: */*
Authorization: fake auth data
Connection: close
User-Agent: HTTP-Tiny/VERSION
X-Custom: This is a custom header
x-lower: This is a lower-case custom header
----------
HTTP/1.1 200 OK
......
url
http://example.com/index.html
expected_rc
599
expected_like
Invalid HTTP header field
headers
trailing-space : foo
----------
----------
......@@ -2,15 +2,16 @@ requires "Carp" => "0";
requires "Fcntl" => "0";
requires "IO::Socket" => "0";
requires "MIME::Base64" => "0";
requires "Socket" => "0";
requires "Time::Local" => "0";
requires "bytes" => "0";
requires "perl" => "5.006";
requires "strict" => "0";
requires "warnings" => "0";
recommends "HTTP::CookieJar" => "0.001";
recommends "IO::Socket::IP" => "0.25";
recommends "IO::Socket::IP" => "0.32";
recommends "IO::Socket::SSL" => "1.42";
recommends "Mozilla::CA" => "20130114";
recommends "Mozilla::CA" => "20160104";
recommends "Net::SSLeay" => "1.49";
suggests "IO::Socket::SSL" => "1.56";
......@@ -39,21 +40,30 @@ on 'configure' => sub {
requires "perl" => "5.006";
};
on 'configure' => sub {
suggests "JSON::PP" => "2.27300";
};
on 'develop' => sub {
requires "Dist::Zilla" => "5";
requires "Dist::Zilla::Plugin::Prereqs" => "0";
requires "Dist::Zilla::Plugin::RemovePrereqs" => "0";
requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.072";
requires "English" => "0";
requires "File::Spec" => "0";
requires "File::Temp" => "0";
requires "IO::Handle" => "0";
requires "IPC::Open3" => "0";
requires "Perl::Critic::Policy::Lax::ProhibitStringyEval::ExceptForRequire" => "0";
requires "Pod::Coverage::TrustPod" => "0";
requires "Pod::Wordlist" => "0";
requires "Software::License::Perl_5" => "0";
requires "Test::CPAN::Meta" => "0";
requires "Test::More" => "0";
requires "Test::Pod" => "1.41";
requires "Test::Pod::Coverage" => "1.08";
requires "Test::Spelling" => "0.12";
requires "Test::Version" => "1";
requires "blib" => "1.01";
requires "perl" => "5.006";
};
......@@ -22,9 +22,9 @@ remove = threads
[Prereqs / Recommends]
HTTP::CookieJar = 0.001
IO::Socket::IP = 0.25
IO::Socket::IP = 0.32
IO::Socket::SSL = 1.42
Mozilla::CA = 20130114
Mozilla::CA = 20160104
Net::SSLeay = 1.49
[Prereqs / Suggests]
......
......@@ -4,7 +4,7 @@ use strict;
use warnings;
# ABSTRACT: A small, simple, correct HTTP/1.1 client
our $VERSION = '0.056';
our $VERSION = '0.058';
use Carp ();
......@@ -15,35 +15,34 @@ use Carp ();
#pod This constructor returns a new HTTP::Tiny object. Valid attributes include:
#pod
#pod =for :list
#pod * C<agent> —
#pod A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If C<agent> — ends in a space character, the default user-agent string is appended.
#pod * C<cookie_jar> —
#pod An instance of L<HTTP::CookieJar> — or equivalent class that supports the C<add> and C<cookie_header> methods
#pod * C<default_headers> —
#pod A hashref of default headers to apply to requests
#pod * C<local_address> —
#pod The local IP address to bind to
#pod * C<keep_alive> —
#pod Whether to reuse the last connection (if for the same scheme, host and port) (defaults to 1)
#pod * C<max_redirect> —
#pod Maximum number of redirects allowed (defaults to 5)
#pod * C<max_size> —
#pod Maximum response size in bytes (only when not using a data callback). If defined, responses larger than this will return an exception.
#pod * C<http_proxy> —
#pod URL of a proxy server to use for HTTP connections (default is C<$ENV{http_proxy}> — if set)
#pod * C<https_proxy> —
#pod URL of a proxy server to use for HTTPS connections (default is C<$ENV{https_proxy}> — if set)
#pod * C<proxy> —
#pod URL of a generic proxy server for both HTTP and HTTPS connections (default is C<$ENV{all_proxy}> — if set)
#pod * C<no_proxy> —
#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<timeout> —
#pod Request timeout in seconds (default is 60)
#pod * C<verify_SSL> —
#pod A boolean that indicates whether to validate the SSL certificate of an C<https> —
#pod connection (default is false)
#pod * C<SSL_options> —
#pod A hashref of C<SSL_*> — options to pass through to L<IO::Socket::SSL>
#pod * C<agent> — A user-agent string (defaults to 'HTTP-Tiny/$VERSION'). If
#pod C<agent> — ends in a space character, the default user-agent string is
#pod appended.
#pod * C<cookie_jar> — An instance of L<HTTP::CookieJar> — or equivalent class
#pod that supports the C<add> and C<cookie_header> methods
#pod * C<default_headers> — A hashref of default headers to apply to requests
#pod * C<local_address> — The local IP address to bind to
#pod * C<keep_alive> — Whether to reuse the last connection (if for the same
#pod scheme, host and port) (defaults to 1)
#pod * C<max_redirect> — Maximum number of redirects allowed (defaults to 5)
#pod * C<max_size> — Maximum response size in bytes (only when not using a data
#pod callback). If defined, responses larger than this will return an
#pod exception.
#pod * C<http_proxy> — URL of a proxy server to use for HTTP connections
#pod (default is C<$ENV{http_proxy}> — if set)
#pod * C<https_proxy> — URL of a proxy server to use for HTTPS connections
#pod (default is C<$ENV{https_proxy}> — if set)
#pod * C<proxy> — URL of a generic proxy server for both HTTP and HTTPS
#pod connections (default is C<$ENV{all_proxy}> — if set)
#pod * C<no_proxy> — List of domain suffixes that should not be proxied. Must
#pod be a comma-separated string or an array reference. (default is
#pod C<$ENV{no_proxy}> —)
#pod * C<timeout> — Request timeout in seconds (default is 60) If a socket open,
#pod read or write takes longer than the timeout, an exception is thrown.
#pod * C<verify_SSL> — A boolean that indicates whether to validate the SSL
#pod certificate of an C<https> — connection (default is false)
#pod * C<SSL_options> — A hashref of C<SSL_*> — options to pass through to
#pod L<IO::Socket::SSL>
#pod
#pod Passing an explicit C<undef> for C<proxy>, C<http_proxy> or C<https_proxy> will
#pod prevent getting the corresponding proxies from the environment.
......@@ -66,7 +65,7 @@ my @attributes;
BEGIN {
@attributes = qw(
cookie_jar default_headers http_proxy https_proxy keep_alive
local_address max_redirect max_size proxy no_proxy timeout
local_address max_redirect max_size proxy no_proxy
SSL_options verify_SSL
);
my %persist_ok = map {; $_ => 1 } qw(
......@@ -95,6 +94,17 @@ sub agent {
return $self->{agent};
}
sub timeout {
my ($self, $timeout) = @_;
if ( @_ > 1 ) {
$self->{timeout} = $timeout;
if ($self->{handle}) {
$self->{handle}->timeout($timeout);
}
}
return $self->{timeout};
}
sub new {
my($class, %args) = @_;
......@@ -337,6 +347,11 @@ sub mirror {
#pod * C<data_callback> —
#pod A code reference that will be called for each chunks of the response
#pod body received.
#pod * C<peer> —
#pod Override host resolution and force all connections to go only to a
#pod specific peer address, regardless of the URL of the request. This will
#pod include any redirections! This options should be used with extreme
#pod caution (e.g. debugging or very special circumstances).
#pod
#pod The C<Host> header is generated from the URL in accordance with RFC 2616. It
#pod is a fatal error to specify C<Host> in the C<headers> option. Other headers
......@@ -378,6 +393,10 @@ sub mirror {
#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 * C<redirects>
#pod If this field exists, it is an arrayref of response hash references from
#pod redirects in the same order that redirections occurred. If it does
#pod not exist, then no redirections occurred.
#pod
#pod On an exception during the execution of the request, the C<status> field will
#pod contain 599, and the C<content> field will contain the text of the exception.
......@@ -511,6 +530,41 @@ sub can_ssl {
wantarray ? ($ok, $reason) : $ok;
}
#pod =method connected
#pod
#pod $host = $http->connected;
#pod ($host, $port) = $http->connected;
#pod
#pod Indicates if a connection to a peer is being kept alive, per the C<keep_alive>
#pod option.
#pod
#pod In scalar context, returns the peer host and port, joined with a colon, or
#pod C<undef> (if no peer is connected).
#pod In list context, returns the peer host and port or an empty list (if no peer
#pod is connected).
#pod
#pod B<Note>: This method cannot reliably be used to discover whether the remote
#pod host has closed its end of the socket.
#pod
#pod =cut
sub connected {
my ($self) = @_;
# If a socket exists...
if ($self->{handle} && $self->{handle}{fh}) {
my $socket = $self->{handle}{fh};
# ...and is connected, return the peer host and port.
if ($socket->connected) {
return wantarray
? ($socket->peerhost, $socket->peerport)
: join(':', $socket->peerhost, $socket->peerport);
}
}
return;
}
#--------------------------------------------------------------------------#
# private methods
#--------------------------------------------------------------------------#
......@@ -541,17 +595,19 @@ sub _request {
headers => {},
};
my $peer = $args->{peer} || $host;
# We remove the cached handle so it is not reused in the case of redirect.
# If all is well, it will be recached at the end of _request. We only
# reuse for the same scheme, host and port
my $handle = delete $self->{handle};
if ( $handle ) {
unless ( $handle->can_reuse( $scheme, $host, $port ) ) {
unless ( $handle->can_reuse( $scheme, $host, $port, $peer ) ) {
$handle->close;
undef $handle;
}
}
$handle ||= $self->_open_handle( $request, $scheme, $host, $port );
$handle ||= $self->_open_handle( $request, $scheme, $host, $port, $peer );
$self->_prepare_headers_and_cb($request, $args, $url, $auth);
$handle->write_request($request);
......@@ -561,11 +617,7 @@ sub _request {
until (substr($response->{status},0,1) ne '1');
$self->_update_cookie_jar( $url, $response ) if $self->{cookie_jar};
if ( my @redir_args = $self->_maybe_redirect($request, $response, $args) ) {
$handle->close;
return $self->_request(@redir_args, $args);
}
my @redir_args = $self->_maybe_redirect($request, $response, $args);
my $known_message_length;
if ($method eq 'HEAD' || $response->{status} =~ /^[23]04/) {
......@@ -573,7 +625,9 @@ sub _request {
$known_message_length = 1;
}
else {
my $data_cb = $self->_prepare_data_cb($response, $args);
# Ignore any data callbacks during redirection.
my $cb_args = @redir_args ? +{} : $args;
my $data_cb = $self->_prepare_data_cb($response, $cb_args);
$known_message_length = $handle->read_body($data_cb, $response);
}
......@@ -590,11 +644,21 @@ sub _request {
$response->{success} = substr( $response->{status}, 0, 1 ) eq '2';
$response->{url} = $url;
# Push the current response onto the stack of redirects if redirecting.
if (@redir_args) {
push @{$args->{_redirects}}, $response;
return $self->_request(@redir_args, $args);
}
# Copy the stack of redirects into the response before returning.
$response->{redirects} = delete $args->{_redirects}
if @{$args->{_redirects}};
return $response;