From cf67fb646ad0efd61d2e4f27cdff5e20fc595a9d Mon Sep 17 00:00:00 2001 From: Steffen Ullrich Date: Fri, 9 Jan 2015 23:42:44 +0100 Subject: [PATCH 01/52] replace EGAIN with EWOULDBLOCK - these are same on UNIX but on Windows you need the latter one --- lib/Net/HTTP.pm | 4 ++-- lib/Net/HTTP/Methods.pm | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index 613bc959..31e77376 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -239,8 +239,8 @@ could be returned this time, otherwise the number of bytes assigned to $buf. The $buf is set to "" when the return value is -1. You normally want to retry this call if this function returns either --1 or C with C<$!> as EINTR or EAGAIN (see L). EINTR -can happen if the application catches signals and EAGAIN can happen if +-1 or C with C<$!> as EINTR or EWOULDBLOCK (see L). EINTR +can happen if the application catches signals and EWOULDBLOCK can happen if you made the socket non-blocking. This method will raise exceptions (die) if the server does not speak diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 649f9af1..28354618 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -270,7 +270,7 @@ sub my_readline { die "read timeout" unless $self->can_read; my $n = $self->sysread($_, 1024, length); unless (defined $n) { - redo READ if $!{EINTR} || $!{EAGAIN}; + redo READ if $!{EINTR} || $!{EWOULDBLOCK}; # if we have already accumulated some data let's at least # return that as a line die "$what read failed: $!" unless length; @@ -308,8 +308,8 @@ sub can_read { $before = time if $timeout; my $nfound = select($fbits, undef, undef, $timeout); if ($nfound < 0) { - if ($!{EINTR} || $!{EAGAIN}) { - # don't really think EAGAIN can happen here + if ($!{EINTR} || $!{EWOULDBLOCK}) { + # don't really think EWOULDBLOCK can happen here if ($timeout) { $timeout -= time - $before; $timeout = 0 if $timeout < 0; From f3661917531be052a0f8e6a1044d30ac9daa8b27 Mon Sep 17 00:00:00 2001 From: Jean-Louis Martineau Date: Tue, 29 Apr 2014 17:32:04 -0400 Subject: [PATCH 02/52] fix-net-ssl-1 --- lib/Net/HTTP/Methods.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 28354618..6baa7cf2 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -295,6 +295,7 @@ sub can_read { my $self = shift; return 1 unless defined(fileno($self)); return 1 if $self->isa('IO::Socket::SSL') && $self->pending; + return 1 if $self->isa('Net::SSL') && $self->pending; # With no timeout, wait forever. An explicit timeout of 0 can be # used to just check if the socket is readable without waiting. From 9e81d4f9d0b4a99a5f1b7b40ca3499c64282541c Mon Sep 17 00:00:00 2001 From: Steffen Ullrich Date: Tue, 27 Jan 2015 23:26:25 +0100 Subject: [PATCH 03/52] check EAGAIN too where EWOULDBLOCK gets checked (mostly same on UNIX, but not on Windows) --- lib/Net/HTTP.pm | 6 +++--- lib/Net/HTTP/Methods.pm | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index 31e77376..be8edb42 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -239,9 +239,9 @@ could be returned this time, otherwise the number of bytes assigned to $buf. The $buf is set to "" when the return value is -1. You normally want to retry this call if this function returns either --1 or C with C<$!> as EINTR or EWOULDBLOCK (see L). EINTR -can happen if the application catches signals and EWOULDBLOCK can happen if -you made the socket non-blocking. +-1 or C with C<$!> as EINTR or EWOULDBLOCK/EAGAIN (see L). +EINTR can happen if the application catches signals and EWOULDBLOCK/EAGAIN +can happen if you made the socket non-blocking. This method will raise exceptions (die) if the server does not speak proper HTTP. This can only happen when reading chunked data. diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 6baa7cf2..56320b0a 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -270,7 +270,7 @@ sub my_readline { die "read timeout" unless $self->can_read; my $n = $self->sysread($_, 1024, length); unless (defined $n) { - redo READ if $!{EINTR} || $!{EWOULDBLOCK}; + redo READ if $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}; # if we have already accumulated some data let's at least # return that as a line die "$what read failed: $!" unless length; @@ -309,8 +309,8 @@ sub can_read { $before = time if $timeout; my $nfound = select($fbits, undef, undef, $timeout); if ($nfound < 0) { - if ($!{EINTR} || $!{EWOULDBLOCK}) { - # don't really think EWOULDBLOCK can happen here + if ($!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}) { + # don't really think EWOULDBLOCK/EAGAIN can happen here if ($timeout) { $timeout -= time - $before; $timeout = 0 if $timeout < 0; From c5da807f3cbd8402a570ace112de2d99012f17cb Mon Sep 17 00:00:00 2001 From: Tom Hukins Date: Tue, 24 Feb 2015 11:24:09 +0000 Subject: [PATCH 04/52] Fix a typo --- lib/Net/HTTP.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index be8edb42..bec499d4 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -95,7 +95,7 @@ C's as well as these: The C option is also the default for C's C. The C defaults to 80 if not provided. The C specification can also be embedded in the C -by preceding it with a ":", and closing the IPv6 address on bracktes "[]" if +by preceding it with a ":", and closing the IPv6 address on brackets "[]" if necessary: "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". The C option provided by C's constructor From e8d75c5e03d8192546a574227d163ed8f3147d71 Mon Sep 17 00:00:00 2001 From: Mark Overmeer Date: Fri, 1 May 2015 13:01:52 -0700 Subject: [PATCH 05/52] fix for SSL bug (RT#104122) --- lib/Net/HTTP/Methods.pm | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 56320b0a..2291ef6a 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -265,20 +265,34 @@ sub my_readline { if $max_line_length && length($_) > $max_line_length; # need to read more data to find a line ending + my $new_bytes = 0; + READ: - { - die "read timeout" unless $self->can_read; - my $n = $self->sysread($_, 1024, length); - unless (defined $n) { - redo READ if $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}; - # if we have already accumulated some data let's at least - # return that as a line - die "$what read failed: $!" unless length; - } - unless ($n) { - return undef unless length; - return substr($_, 0, length, ""); + { # wait until bytes start arriving + $self->can_read + or die "read timeout"; + + # consume all incoming bytes + while(1) { + my $bytes_read = $self->sysread($_, 1024, length); + if(defined $bytes_read) { + $new_bytes += $bytes_read; + last if $bytes_read < 1024; + } + elsif($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { + redo READ; + } + else { + # if we have already accumulated some data let's at + # least return that as a line + length or die "$what read failed: $!"; + last; + } } + + # no line-ending, no new bytes + return length($_) ? substr($_, 0, length($_), "") : undef + if $new_bytes==0; } } die "$what line too long ($pos; limit is $max_line_length)" From 4e9bbb92e6134ad355697a862546d3fdd4e2e8ea Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 13:13:02 -0700 Subject: [PATCH 06/52] ignore new ExtUtils::MakeMaker artifact --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e4d0dc1f..13207126 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ t/CAN_TALK_TO_OURSELF t/live/ENABLED *.tar.gz xx* +/_eumm/ From f72cd3168941eb160dc19efa8fe2c9c8a12c16c2 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 13:13:21 -0700 Subject: [PATCH 07/52] ignore MYMETA files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 13207126..84f2dadc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ t/live/ENABLED *.tar.gz xx* /_eumm/ +/MYMETA.* From 51f05dd7e434ee10991bf4f6b0a8ed997788139e Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 13:16:41 -0700 Subject: [PATCH 08/52] changelog entry for RT#104122 --- Changes | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Changes b/Changes index 8a064c77..9836041a 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,20 @@ + + +Mark Overmeer (1): + resolve issues with SSL by reading bytes still waiting to be read after + the initial 1024 bytes [RT#104122] + + + +_______________________________________________________________________________ 2014-07-23 Net-HTTP 6.07 Jason Fesler (1): Opportunistically use IO::Socket::IP or IO::Socket::INET6. Properly parse IPv6 literal addreses with optional port numbers. [RT#75618] + + _______________________________________________________________________________ 2013-03-10 Net-HTTP 6.06 From ec736fb782c9df89de01bc906fc7c8607dd8159b Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 13:48:48 -0700 Subject: [PATCH 09/52] bump all versions to 6.08_001 --- lib/Net/HTTP.pm | 4 +++- lib/Net/HTTP/Methods.pm | 3 ++- lib/Net/HTTP/NB.pm | 3 ++- lib/Net/HTTPS.pm | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index bec499d4..a1978030 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -3,7 +3,9 @@ package Net::HTTP; use strict; use vars qw($VERSION @ISA $SOCKET_CLASS); -$VERSION = "6.07"; +$VERSION = "6.08_001"; +$VERSION = eval $VERSION; + unless ($SOCKET_CLASS) { # Try several, in order of capability and preference if (eval { require IO::Socket::IP }) { diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 2291ef6a..463628bb 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -6,7 +6,8 @@ use strict; use vars qw($VERSION); use URI; -$VERSION = "6.07"; +$VERSION = "6.08_001"; +eval $VERSION = $VERSION; my $CRLF = "\015\012"; # "\r\n" is not portable diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index 3c465a8c..11001eea 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -3,7 +3,8 @@ package Net::HTTP::NB; use strict; use vars qw($VERSION @ISA); -$VERSION = "6.04"; +$VERSION = "6.08_001"; +eval $VERSION = $VERSION; require Net::HTTP; @ISA=qw(Net::HTTP); diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 87ecf485..408a0810 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -3,7 +3,8 @@ package Net::HTTPS; use strict; use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); -$VERSION = "6.04"; +$VERSION = "6.08_001"; +eval $VERSION = $VERSION; # Figure out which SSL implementation to use if ($SSL_SOCKET_CLASS) { From 245c64e10ad105cbf18a7175aa2dc84b128c8727 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 13:49:18 -0700 Subject: [PATCH 10/52] mark the 6.08_001 release in the changelog --- Changes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changes b/Changes index 9836041a..481135eb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ +Release history for Net-HTTP +_______________________________________________________________________________ +2015-05-01 Net-HTTP 6.08_001 + Mark Overmeer (1): resolve issues with SSL by reading bytes still waiting to be read after the initial 1024 bytes [RT#104122] From ce9b0b8b172d59f88d684b9284464c6bb1429dc1 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 14:09:50 -0700 Subject: [PATCH 11/52] use v2 metaspec to specify metadata; add more resources --- Makefile.PL | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 31916246..331269f7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,23 +19,38 @@ WriteMakefile( VERSION_FROM => 'lib/Net/HTTP.pm', ABSTRACT_FROM => 'lib/Net/HTTP.pm', AUTHOR => 'Gisle Aas ', - LICENSE => "perl", + LICENSE => 'perl_5', MIN_PERL_VERSION => 5.006002, PREREQ_PM => { - 'IO::Socket::INET' => 0, - 'IO::Select' => 0, + 'IO::Socket::INET' => 0, + 'IO::Select' => 0, 'Compress::Raw::Zlib' => 0, 'IO::Uncompress::Gunzip' => 0, 'URI' => 0, }, META_MERGE => { - recommends => { - 'IO::Socket::SSL' => "1.38", + 'meta-spec' => { version => 2 }, + dynamic_config => 0, + prereqs => { + runtime => { + recommends => { + 'IO::Socket::SSL' => "1.38", + }, + }, + }, + resources => { + repository => { + url => 'https://github.com/libwww-perl/net-http.git', + web => 'https://github.com/libwww-perl/net-http', + type => 'git', + }, + bugtracker => { + mailto => 'bug-Net-HTTP@rt.cpan.org', + web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Net-HTTP', + }, + x_MailingList => 'mailto:libwww@perl.org', + x_IRC => 'irc://irc.perl.org/#lwp', }, - resources => { - repository => 'http://github.com/libwww-perl/net-http', - MailingList => 'mailto:libwww@perl.org', - } }, ); From 063f84b009d2e7eea2baef138eec26f5ce55bfe0 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 20:07:57 -0700 Subject: [PATCH 12/52] doh, how could I have messed up this syntax... --- Changes | 5 +++++ lib/Net/HTTP/Methods.pm | 2 +- lib/Net/HTTP/NB.pm | 2 +- lib/Net/HTTPS.pm | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 481135eb..ac0254f4 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Release history for Net-HTTP +Karen Etheridge (1): + fix foolish $VERSION error in 6.08_001 + + + _______________________________________________________________________________ 2015-05-01 Net-HTTP 6.08_001 diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 463628bb..f9d07f9f 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -7,7 +7,7 @@ use vars qw($VERSION); use URI; $VERSION = "6.08_001"; -eval $VERSION = $VERSION; +$VERSION = eval $VERSION; my $CRLF = "\015\012"; # "\r\n" is not portable diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index 11001eea..0fdb2c07 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -4,7 +4,7 @@ use strict; use vars qw($VERSION @ISA); $VERSION = "6.08_001"; -eval $VERSION = $VERSION; +$VERSION = eval $VERSION; require Net::HTTP; @ISA=qw(Net::HTTP); diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 408a0810..c515ad06 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -4,7 +4,7 @@ use strict; use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); $VERSION = "6.08_001"; -eval $VERSION = $VERSION; +$VERSION = eval $VERSION; # Figure out which SSL implementation to use if ($SSL_SOCKET_CLASS) { From fb8a87a3635f0e142d84b3f2d0a315b31015f7da Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 20:08:46 -0700 Subject: [PATCH 13/52] ignore older build directories, more build artifacts --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 84f2dadc..866799e0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ t/live/ENABLED xx* /_eumm/ /MYMETA.* +/MANIFEST.bak +/Net-HTTP-*/ +/Net-HTTP-*.tar.gz From 4bb6d3b1f3fadb14d2a82d1436e372b5b300a145 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 20:13:40 -0700 Subject: [PATCH 14/52] sort the MANIFEST as ExtUtils::Manifest does --- MANIFEST | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MANIFEST b/MANIFEST index 74d3a55b..14196dbd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,7 +6,7 @@ lib/Net/HTTPS.pm Makefile.PL MANIFEST This list of files README -t/http.t -t/http-nb.t -t/apache.t t/apache-https.t +t/apache.t +t/http-nb.t +t/http.t From 4ed4e011e345c7c1b18f5d83cb6963de78553e2f Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 1 May 2015 20:10:21 -0700 Subject: [PATCH 15/52] bump version to 6.08_002 --- Changes | 2 ++ lib/Net/HTTP.pm | 2 +- lib/Net/HTTP/Methods.pm | 2 +- lib/Net/HTTP/NB.pm | 2 +- lib/Net/HTTPS.pm | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index ac0254f4..1e85ef39 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Release history for Net-HTTP +2015-05-02 Net-HTTP 6.08_002 + Karen Etheridge (1): fix foolish $VERSION error in 6.08_001 diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index a1978030..c5e14ef7 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -3,7 +3,7 @@ package Net::HTTP; use strict; use vars qw($VERSION @ISA $SOCKET_CLASS); -$VERSION = "6.08_001"; +$VERSION = "6.08_002"; $VERSION = eval $VERSION; unless ($SOCKET_CLASS) { diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index f9d07f9f..0157ab75 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -6,7 +6,7 @@ use strict; use vars qw($VERSION); use URI; -$VERSION = "6.08_001"; +$VERSION = "6.08_002"; $VERSION = eval $VERSION; my $CRLF = "\015\012"; # "\r\n" is not portable diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index 0fdb2c07..78425731 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -3,7 +3,7 @@ package Net::HTTP::NB; use strict; use vars qw($VERSION @ISA); -$VERSION = "6.08_001"; +$VERSION = "6.08_002"; $VERSION = eval $VERSION; require Net::HTTP; diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index c515ad06..ecbc1fad 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -3,7 +3,7 @@ package Net::HTTPS; use strict; use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); -$VERSION = "6.08_001"; +$VERSION = "6.08_002"; $VERSION = eval $VERSION; # Figure out which SSL implementation to use From 0896c0c41a87ce919d1a99a7a4f7152b033be072 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 20 May 2015 11:44:54 -0700 Subject: [PATCH 16/52] add a basic MANIFEST.SKIP --- .gitignore | 1 + MANIFEST | 1 + MANIFEST.SKIP | 5 +++++ 3 files changed, 7 insertions(+) create mode 100644 MANIFEST.SKIP diff --git a/.gitignore b/.gitignore index 866799e0..3c50b513 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,6 @@ xx* /_eumm/ /MYMETA.* /MANIFEST.bak +/MANIFEST.SKIP.bak /Net-HTTP-*/ /Net-HTTP-*.tar.gz diff --git a/MANIFEST b/MANIFEST index 14196dbd..6499ae8c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,6 +5,7 @@ lib/Net/HTTP/NB.pm lib/Net/HTTPS.pm Makefile.PL MANIFEST This list of files +MANIFEST.SKIP README t/apache-https.t t/apache.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 00000000..b1d2cbff --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,5 @@ +#!include_default + +\.ackrc +Net-HTTP-.*/ +Net-HTTP-.*.tar.gz From 2f5e482325731aeaaa3ce19900e35540f77cc76b Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 20 May 2015 11:42:40 -0700 Subject: [PATCH 17/52] bump version to 6.09 --- lib/Net/HTTP.pm | 2 +- lib/Net/HTTP/Methods.pm | 2 +- lib/Net/HTTP/NB.pm | 2 +- lib/Net/HTTPS.pm | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index c5e14ef7..4d0f4500 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -3,7 +3,7 @@ package Net::HTTP; use strict; use vars qw($VERSION @ISA $SOCKET_CLASS); -$VERSION = "6.08_002"; +$VERSION = "6.09"; $VERSION = eval $VERSION; unless ($SOCKET_CLASS) { diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 0157ab75..250d2509 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -6,7 +6,7 @@ use strict; use vars qw($VERSION); use URI; -$VERSION = "6.08_002"; +$VERSION = "6.09"; $VERSION = eval $VERSION; my $CRLF = "\015\012"; # "\r\n" is not portable diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index 78425731..d908cf8f 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -3,7 +3,7 @@ package Net::HTTP::NB; use strict; use vars qw($VERSION @ISA); -$VERSION = "6.08_002"; +$VERSION = "6.09"; $VERSION = eval $VERSION; require Net::HTTP; diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index ecbc1fad..10c5c8a9 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -3,7 +3,7 @@ package Net::HTTPS; use strict; use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); -$VERSION = "6.08_002"; +$VERSION = "6.09"; $VERSION = eval $VERSION; # Figure out which SSL implementation to use From 45b4f1aed02ddbd91dc95aa7b6018c527ce4b0ac Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 20 May 2015 11:43:29 -0700 Subject: [PATCH 18/52] changelog for 6.09 --- Changes | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Changes b/Changes index 1e85ef39..1a90727a 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,15 @@ Release history for Net-HTTP +_______________________________________________________________________________ +2015-05-20 Net-HTTP 6.09 + +Karen Etheridge (1): + No changes since 6.08_002 + + + +_______________________________________________________________________________ 2015-05-02 Net-HTTP 6.08_002 Karen Etheridge (1): From 230ce0b9b4102a2f1e66a467fe794d1adae72738 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 20 May 2015 12:52:10 -0700 Subject: [PATCH 19/52] refresh README --- README | 283 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 154 insertions(+), 129 deletions(-) diff --git a/README b/README index 6b5217d3..45356c65 100644 --- a/README +++ b/README @@ -1,12 +1,14 @@ NAME + Net::HTTP - Low-level HTTP connection (client) SYNOPSIS + use Net::HTTP; my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); my($code, $mess, %h) = $s->read_response_headers; - + while (1) { my $buf; my $n = $s->read_entity_body($buf, 1024); @@ -16,200 +18,223 @@ SYNOPSIS } DESCRIPTION - The `Net::HTTP' class is a low-level HTTP client. An instance of the - `Net::HTTP' class represents a connection to an HTTP server. The HTTP - protocol is described in RFC 2616. The `Net::HTTP' class supports - `HTTP/1.0' and `HTTP/1.1'. - `Net::HTTP' is a sub-class of `IO::Socket::INET'. You can mix the - methods described below with reading and writing from the socket - directly. This is not necessary a good idea, unless you know what you - are doing. + The Net::HTTP class is a low-level HTTP client. An instance of the + Net::HTTP class represents a connection to an HTTP server. The HTTP + protocol is described in RFC 2616. The Net::HTTP class supports + HTTP/1.0 and HTTP/1.1. + + Net::HTTP is a sub-class of one of IO::Socket::IP (IPv6+IPv4), + IO::Socket::INET6 (IPv6+IPv4), or IO::Socket::INET (IPv4 only). You can + mix the methods described below with reading and writing from the + socket directly. This is not necessary a good idea, unless you know + what you are doing. The following methods are provided (in addition to those of - `IO::Socket::INET'): + IO::Socket::INET): $s = Net::HTTP->new( %options ) - The `Net::HTTP' constructor method takes the same options as - `IO::Socket::INET''s as well as these: - Host: Initial host attribute value - KeepAlive: Initial keep_alive attribute value - SendTE: Initial send_te attribute_value - HTTPVersion: Initial http_version attribute value - PeerHTTPVersion: Initial peer_http_version attribute value - MaxLineLength: Initial max_line_length attribute value - MaxHeaderLines: Initial max_header_lines attribute value + The Net::HTTP constructor method takes the same options as + IO::Socket::INET's as well as these: - The `Host' option is also the default for `IO::Socket::INET''s - `PeerAddr'. The `PeerPort' defaults to 80 if not provided. + Host: Initial host attribute value + KeepAlive: Initial keep_alive attribute value + SendTE: Initial send_te attribute_value + HTTPVersion: Initial http_version attribute value + PeerHTTPVersion: Initial peer_http_version attribute value + MaxLineLength: Initial max_line_length attribute value + MaxHeaderLines: Initial max_header_lines attribute value - The `Listen' option provided by `IO::Socket::INET''s constructor - method is not allowed. + The Host option is also the default for IO::Socket::INET's PeerAddr. + The PeerPort defaults to 80 if not provided. The PeerPort + specification can also be embedded in the PeerAddr by preceding it + with a ":", and closing the IPv6 address on brackets "[]" if + necessary: "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". - If unable to connect to the given HTTP server then the constructor - returns `undef' and $@ contains the reason. After a successful - connect, a `Net:HTTP' object is returned. + The Listen option provided by IO::Socket::INET's constructor method + is not allowed. + + If unable to connect to the given HTTP server then the constructor + returns undef and $@ contains the reason. After a successful connect, + a Net:HTTP object is returned. $s->host - Get/set the default value of the `Host' header to send. The $host - must not be set to an empty string (or `undef') for HTTP/1.1. + + Get/set the default value of the Host header to send. The $host must + not be set to an empty string (or undef) for HTTP/1.1. $s->keep_alive - Get/set the *keep-alive* value. If this value is TRUE then the - request will be sent with headers indicating that the server should - try to keep the connection open so that multiple requests can be - sent. - The actual headers set will depend on the value of the - `http_version' and `peer_http_version' attributes. + Get/set the keep-alive value. If this value is TRUE then the request + will be sent with headers indicating that the server should try to + keep the connection open so that multiple requests can be sent. + + The actual headers set will depend on the value of the http_version + and peer_http_version attributes. $s->send_te - Get/set the a value indicating if the request will be sent with a - "TE" header to indicate the transfer encodings that the server can - choose to use. The list of encodings announced as accepted by this - client depends on availability of the following modules: - `Compress::Raw::Zlib' for *deflate*, and `IO::Compress::Gunzip' for - *gzip*. + + Get/set the a value indicating if the request will be sent with a + "TE" header to indicate the transfer encodings that the server can + choose to use. The list of encodings announced as accepted by this + client depends on availability of the following modules: + Compress::Raw::Zlib for deflate, and IO::Compress::Gunzip for gzip. $s->http_version - Get/set the HTTP version number that this client should announce. - This value can only be set to "1.0" or "1.1". The default is "1.1". + + Get/set the HTTP version number that this client should announce. + This value can only be set to "1.0" or "1.1". The default is "1.1". $s->peer_http_version - Get/set the protocol version number of our peer. This value will - initially be "1.0", but will be updated by a successful - read_response_headers() method call. + + Get/set the protocol version number of our peer. This value will + initially be "1.0", but will be updated by a successful + read_response_headers() method call. $s->max_line_length - Get/set a limit on the length of response line and response header - lines. The default is 8192. A value of 0 means no limit. + + Get/set a limit on the length of response line and response header + lines. The default is 8192. A value of 0 means no limit. $s->max_header_length - Get/set a limit on the number of header lines that a response can - have. The default is 128. A value of 0 means no limit. + + Get/set a limit on the number of header lines that a response can + have. The default is 128. A value of 0 means no limit. $s->format_request($method, $uri, %headers, [$content]) - Format a request message and return it as a string. If the headers - do not include a `Host' header, then a header is inserted with the - value of the `host' attribute. Headers like `Connection' and - `Keep-Alive' might also be added depending on the status of the - `keep_alive' attribute. - If $content is given (and it is non-empty), then a `Content-Length' - header is automatically added unless it was already present. + Format a request message and return it as a string. If the headers do + not include a Host header, then a header is inserted with the value + of the host attribute. Headers like Connection and Keep-Alive might + also be added depending on the status of the keep_alive attribute. + + If $content is given (and it is non-empty), then a Content-Length + header is automatically added unless it was already present. $s->write_request($method, $uri, %headers, [$content]) - Format and send a request message. Arguments are the same as for - format_request(). Returns true if successful. + + Format and send a request message. Arguments are the same as for + format_request(). Returns true if successful. $s->format_chunk( $data ) - Returns the string to be written for the given chunk of data. + + Returns the string to be written for the given chunk of data. $s->write_chunk($data) - Will write a new chunk of request entity body data. This method - should only be used if the `Transfer-Encoding' header with a value - of `chunked' was sent in the request. Note, writing zero-length data - is a no-op. Use the write_chunk_eof() method to signal end of entity - body data. - Returns true if successful. + Will write a new chunk of request entity body data. This method + should only be used if the Transfer-Encoding header with a value of + chunked was sent in the request. Note, writing zero-length data is a + no-op. Use the write_chunk_eof() method to signal end of entity body + data. + + Returns true if successful. $s->format_chunk_eof( %trailers ) - Returns the string to be written for signaling EOF when a - `Transfer-Encoding' of `chunked' is used. + + Returns the string to be written for signaling EOF when a + Transfer-Encoding of chunked is used. $s->write_chunk_eof( %trailers ) - Will write eof marker for chunked data and optional trailers. Note - that trailers should not really be used unless is was signaled with - a `Trailer' header. - Returns true if successful. + Will write eof marker for chunked data and optional trailers. Note + that trailers should not really be used unless is was signaled with a + Trailer header. + + Returns true if successful. ($code, $mess, %headers) = $s->read_response_headers( %opts ) - Read response headers from server and return it. The $code is the 3 - digit HTTP status code (see HTTP::Status) and $mess is the textual - message that came with it. Headers are then returned as key/value - pairs. Since key letter casing is not normalized and the same key - can even occur multiple times, assigning these values directly to a - hash is not wise. Only the $code is returned if this method is - called in scalar context. - - As a side effect this method updates the 'peer_http_version' - attribute. - - Options might be passed in as key/value pairs. There are currently - only two options supported; `laxed' and `junk_out'. - - The `laxed' option will make read_response_headers() more forgiving - towards servers that have not learned how to speak HTTP properly. - The `laxed' option is a boolean flag, and is enabled by passing in a - TRUE value. The `junk_out' option can be used to capture bad header - lines when `laxed' is enabled. The value should be an array - reference. Bad header lines will be pushed onto the array. - - The `laxed' option must be specified in order to communicate with - pre-HTTP/1.0 servers that don't describe the response outcome or the - data they send back with a header block. For these servers - peer_http_version is set to "0.9" and this method returns (200, - "Assumed OK"). - - The method will raise an exception (die) if the server does not - speak proper HTTP or if the `max_line_length' or `max_header_length' - limits are reached. If the `laxed' option is turned on and - `max_line_length' and `max_header_length' checks are turned off, - then no exception will be raised and this method will always return - a response code. + + Read response headers from server and return it. The $code is the 3 + digit HTTP status code (see HTTP::Status) and $mess is the textual + message that came with it. Headers are then returned as key/value + pairs. Since key letter casing is not normalized and the same key can + even occur multiple times, assigning these values directly to a hash + is not wise. Only the $code is returned if this method is called in + scalar context. + + As a side effect this method updates the 'peer_http_version' + attribute. + + Options might be passed in as key/value pairs. There are currently + only two options supported; laxed and junk_out. + + The laxed option will make read_response_headers() more forgiving + towards servers that have not learned how to speak HTTP properly. The + laxed option is a boolean flag, and is enabled by passing in a TRUE + value. The junk_out option can be used to capture bad header lines + when laxed is enabled. The value should be an array reference. Bad + header lines will be pushed onto the array. + + The laxed option must be specified in order to communicate with + pre-HTTP/1.0 servers that don't describe the response outcome or the + data they send back with a header block. For these servers + peer_http_version is set to "0.9" and this method returns (200, + "Assumed OK"). + + The method will raise an exception (die) if the server does not speak + proper HTTP or if the max_line_length or max_header_length limits are + reached. If the laxed option is turned on and max_line_length and + max_header_length checks are turned off, then no exception will be + raised and this method will always return a response code. $n = $s->read_entity_body($buf, $size); - Reads chunks of the entity body content. Basically the same - interface as for read() and sysread(), but the buffer offset - argument is not supported yet. This method should only be called - after a successful read_response_headers() call. - The return value will be `undef' on read errors, 0 on EOF, -1 if no - data could be returned this time, otherwise the number of bytes - assigned to $buf. The $buf is set to "" when the return value is -1. + Reads chunks of the entity body content. Basically the same interface + as for read() and sysread(), but the buffer offset argument is not + supported yet. This method should only be called after a successful + read_response_headers() call. + + The return value will be undef on read errors, 0 on EOF, -1 if no + data could be returned this time, otherwise the number of bytes + assigned to $buf. The $buf is set to "" when the return value is -1. - You normally want to retry this call if this function returns either - -1 or `undef' with `$!' as EINTR or EAGAIN (see Errno). EINTR can - happen if the application catches signals and EAGAIN can happen if - you made the socket non-blocking. + You normally want to retry this call if this function returns either + -1 or undef with $! as EINTR or EAGAIN (see Errno). EINTR can happen + if the application catches signals and EAGAIN can happen if you made + the socket non-blocking. - This method will raise exceptions (die) if the server does not speak - proper HTTP. This can only happen when reading chunked data. + This method will raise exceptions (die) if the server does not speak + proper HTTP. This can only happen when reading chunked data. %headers = $s->get_trailers - After read_entity_body() has returned 0 to indicate end of the - entity body, you might call this method to pick up any trailers. + + After read_entity_body() has returned 0 to indicate end of the entity + body, you might call this method to pick up any trailers. $s->_rbuf - Get/set the read buffer content. The read_response_headers() and - read_entity_body() methods use an internal buffer which they will - look for data before they actually sysread more from the socket - itself. If they read too much, the remaining data will be left in - this buffer. + + Get/set the read buffer content. The read_response_headers() and + read_entity_body() methods use an internal buffer which they will + look for data before they actually sysread more from the socket + itself. If they read too much, the remaining data will be left in + this buffer. $s->_rbuf_length - Returns the number of bytes in the read buffer. This should always - be the same as: - length($s->_rbuf) + Returns the number of bytes in the read buffer. This should always be + the same as: + + length($s->_rbuf) - but might be more efficient. + but might be more efficient. SUBCLASSING + The read_response_headers() and read_entity_body() will invoke the sysread() method when they need more data. Subclasses might want to override this method to control how reading takes place. The object itself is a glob. Subclasses should avoid using hash key - names prefixed with `http_' and `io_'. + names prefixed with http_ and io_. SEE ALSO + LWP, IO::Socket::INET, Net::HTTP::NB COPYRIGHT + Copyright 2001-2003 Gisle Aas. This library is free software; you can redistribute it and/or modify it From 3264f04915e686b64f5f975a14538fa0ad35cc93 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 20 May 2015 12:51:18 -0700 Subject: [PATCH 20/52] add a README.md for github (but do not ship it) --- MANIFEST.SKIP | 1 + README.md | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 README.md diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index b1d2cbff..add4a7a3 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -3,3 +3,4 @@ \.ackrc Net-HTTP-.*/ Net-HTTP-.*.tar.gz +README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..61a2884e --- /dev/null +++ b/README.md @@ -0,0 +1,242 @@ +# NAME + +Net::HTTP - Low-level HTTP connection (client) + +# SYNOPSIS + + use Net::HTTP; + my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; + $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); + my($code, $mess, %h) = $s->read_response_headers; + + while (1) { + my $buf; + my $n = $s->read_entity_body($buf, 1024); + die "read failed: $!" unless defined $n; + last unless $n; + print $buf; + } + +# DESCRIPTION + +The `Net::HTTP` class is a low-level HTTP client. An instance of the +`Net::HTTP` class represents a connection to an HTTP server. The +HTTP protocol is described in RFC 2616. The `Net::HTTP` class +supports `HTTP/1.0` and `HTTP/1.1`. + +`Net::HTTP` is a sub-class of one of `IO::Socket::IP` (IPv6+IPv4), +`IO::Socket::INET6` (IPv6+IPv4), or `IO::Socket::INET` (IPv4 only). +You can mix the methods described below with reading and writing from the +socket directly. This is not necessary a good idea, unless you know what +you are doing. + +The following methods are provided (in addition to those of +`IO::Socket::INET`): + +- $s = Net::HTTP->new( %options ) + + The `Net::HTTP` constructor method takes the same options as + `IO::Socket::INET`'s as well as these: + + Host: Initial host attribute value + KeepAlive: Initial keep_alive attribute value + SendTE: Initial send_te attribute_value + HTTPVersion: Initial http_version attribute value + PeerHTTPVersion: Initial peer_http_version attribute value + MaxLineLength: Initial max_line_length attribute value + MaxHeaderLines: Initial max_header_lines attribute value + + The `Host` option is also the default for `IO::Socket::INET`'s + `PeerAddr`. The `PeerPort` defaults to 80 if not provided. + The `PeerPort` specification can also be embedded in the `PeerAddr` + by preceding it with a ":", and closing the IPv6 address on brackets "\[\]" if + necessary: "192.0.2.1:80","\[2001:db8::1\]:80","any.example.com:80". + + The `Listen` option provided by `IO::Socket::INET`'s constructor + method is not allowed. + + If unable to connect to the given HTTP server then the constructor + returns `undef` and $@ contains the reason. After a successful + connect, a `Net:HTTP` object is returned. + +- $s->host + + Get/set the default value of the `Host` header to send. The $host + must not be set to an empty string (or `undef`) for HTTP/1.1. + +- $s->keep\_alive + + Get/set the _keep-alive_ value. If this value is TRUE then the + request will be sent with headers indicating that the server should try + to keep the connection open so that multiple requests can be sent. + + The actual headers set will depend on the value of the `http_version` + and `peer_http_version` attributes. + +- $s->send\_te + + Get/set the a value indicating if the request will be sent with a "TE" + header to indicate the transfer encodings that the server can choose to + use. The list of encodings announced as accepted by this client depends + on availability of the following modules: `Compress::Raw::Zlib` for + _deflate_, and `IO::Compress::Gunzip` for _gzip_. + +- $s->http\_version + + Get/set the HTTP version number that this client should announce. + This value can only be set to "1.0" or "1.1". The default is "1.1". + +- $s->peer\_http\_version + + Get/set the protocol version number of our peer. This value will + initially be "1.0", but will be updated by a successful + read\_response\_headers() method call. + +- $s->max\_line\_length + + Get/set a limit on the length of response line and response header + lines. The default is 8192. A value of 0 means no limit. + +- $s->max\_header\_length + + Get/set a limit on the number of header lines that a response can + have. The default is 128. A value of 0 means no limit. + +- $s->format\_request($method, $uri, %headers, \[$content\]) + + Format a request message and return it as a string. If the headers do + not include a `Host` header, then a header is inserted with the value + of the `host` attribute. Headers like `Connection` and + `Keep-Alive` might also be added depending on the status of the + `keep_alive` attribute. + + If $content is given (and it is non-empty), then a `Content-Length` + header is automatically added unless it was already present. + +- $s->write\_request($method, $uri, %headers, \[$content\]) + + Format and send a request message. Arguments are the same as for + format\_request(). Returns true if successful. + +- $s->format\_chunk( $data ) + + Returns the string to be written for the given chunk of data. + +- $s->write\_chunk($data) + + Will write a new chunk of request entity body data. This method + should only be used if the `Transfer-Encoding` header with a value of + `chunked` was sent in the request. Note, writing zero-length data is + a no-op. Use the write\_chunk\_eof() method to signal end of entity + body data. + + Returns true if successful. + +- $s->format\_chunk\_eof( %trailers ) + + Returns the string to be written for signaling EOF when a + `Transfer-Encoding` of `chunked` is used. + +- $s->write\_chunk\_eof( %trailers ) + + Will write eof marker for chunked data and optional trailers. Note + that trailers should not really be used unless is was signaled + with a `Trailer` header. + + Returns true if successful. + +- ($code, $mess, %headers) = $s->read\_response\_headers( %opts ) + + Read response headers from server and return it. The $code is the 3 + digit HTTP status code (see [HTTP::Status](https://metacpan.org/pod/HTTP::Status)) and $mess is the textual + message that came with it. Headers are then returned as key/value + pairs. Since key letter casing is not normalized and the same key can + even occur multiple times, assigning these values directly to a hash + is not wise. Only the $code is returned if this method is called in + scalar context. + + As a side effect this method updates the 'peer\_http\_version' + attribute. + + Options might be passed in as key/value pairs. There are currently + only two options supported; `laxed` and `junk_out`. + + The `laxed` option will make read\_response\_headers() more forgiving + towards servers that have not learned how to speak HTTP properly. The + `laxed` option is a boolean flag, and is enabled by passing in a TRUE + value. The `junk_out` option can be used to capture bad header lines + when `laxed` is enabled. The value should be an array reference. + Bad header lines will be pushed onto the array. + + The `laxed` option must be specified in order to communicate with + pre-HTTP/1.0 servers that don't describe the response outcome or the + data they send back with a header block. For these servers + peer\_http\_version is set to "0.9" and this method returns (200, + "Assumed OK"). + + The method will raise an exception (die) if the server does not speak + proper HTTP or if the `max_line_length` or `max_header_length` + limits are reached. If the `laxed` option is turned on and + `max_line_length` and `max_header_length` checks are turned off, + then no exception will be raised and this method will always + return a response code. + +- $n = $s->read\_entity\_body($buf, $size); + + Reads chunks of the entity body content. Basically the same interface + as for read() and sysread(), but the buffer offset argument is not + supported yet. This method should only be called after a successful + read\_response\_headers() call. + + The return value will be `undef` on read errors, 0 on EOF, -1 if no data + could be returned this time, otherwise the number of bytes assigned + to $buf. The $buf is set to "" when the return value is -1. + + You normally want to retry this call if this function returns either + \-1 or `undef` with `$!` as EINTR or EAGAIN (see [Errno](https://metacpan.org/pod/Errno)). EINTR + can happen if the application catches signals and EAGAIN can happen if + you made the socket non-blocking. + + This method will raise exceptions (die) if the server does not speak + proper HTTP. This can only happen when reading chunked data. + +- %headers = $s->get\_trailers + + After read\_entity\_body() has returned 0 to indicate end of the entity + body, you might call this method to pick up any trailers. + +- $s->\_rbuf + + Get/set the read buffer content. The read\_response\_headers() and + read\_entity\_body() methods use an internal buffer which they will look + for data before they actually sysread more from the socket itself. If + they read too much, the remaining data will be left in this buffer. + +- $s->\_rbuf\_length + + Returns the number of bytes in the read buffer. This should always be + the same as: + + length($s->_rbuf) + + but might be more efficient. + +# SUBCLASSING + +The read\_response\_headers() and read\_entity\_body() will invoke the +sysread() method when they need more data. Subclasses might want to +override this method to control how reading takes place. + +The object itself is a glob. Subclasses should avoid using hash key +names prefixed with `http_` and `io_`. + +# SEE ALSO + +[LWP](https://metacpan.org/pod/LWP), [IO::Socket::INET](https://metacpan.org/pod/IO::Socket::INET), [Net::HTTP::NB](https://metacpan.org/pod/Net::HTTP::NB) + +# COPYRIGHT + +Copyright 2001-2003 Gisle Aas. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. From 8ce6dbb8e3d28e26d4d9622d64aa1162d98a5a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 24 Jun 2015 23:24:25 +0300 Subject: [PATCH 21/52] Spelling and grammar fixes --- Changes | 2 +- lib/Net/HTTPS.pm | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 1a90727a..ef070226 100644 --- a/Changes +++ b/Changes @@ -78,7 +78,7 @@ _______________________________________________________________________________ Restore blocking override for Net::SSL [RT#72790] -Restore perl-5.6 compatiblity. +Restore perl-5.6 compatibility. _______________________________________________________________________________ diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 10c5c8a9..96dd288e 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -89,9 +89,9 @@ Net::HTTPS - Low-level HTTP over SSL/TLS connection (client) =head1 DESCRIPTION The C is a low-level HTTP over SSL/TLS client. The interface is the same -as the interface for C, but the constructor method take additional parameters -as accepted by L. The C object isa C -too, which make it inherit additional methods from that base class. +as the interface for C, but the constructor takes additional parameters +as accepted by L. The C object is an C +too, which makes it inherit additional methods from that base class. For historical reasons this module also supports using C (from the Crypt-SSLeay distribution) as its SSL driver and base class. This base is From 46d94f5bfa2a604ce7424b6f1a9e8c9eaab9a937 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:33:23 -0700 Subject: [PATCH 22/52] create LICENSE software-license --holder 'Gisle Aas' --license Perl_5 --type fulltext --year 2011 > LICENSE --- Changes | 5 + LICENSE | 379 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ MANIFEST | 1 + 3 files changed, 385 insertions(+) create mode 100644 LICENSE diff --git a/Changes b/Changes index ef070226..13386521 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Release history for Net-HTTP +Karen Etheridge (1): + Added LICENSE + + + _______________________________________________________________________________ 2015-05-20 Net-HTTP 6.09 diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..deecb6d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,379 @@ +This software is copyright (c) 2011 by Gisle Aas. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +Terms of the Perl programming language system itself + +a) the GNU General Public License as published by the Free + Software Foundation; either version 1, or (at your option) any + later version, or +b) the "Artistic License" + +--- The GNU General Public License, Version 1, February 1989 --- + +This software is Copyright (c) 2011 by Gisle Aas. + +This is free software, licensed under: + + The GNU General Public License, Version 1, February 1989 + + GNU GENERAL PUBLIC LICENSE + Version 1, February 1989 + + Copyright (C) 1989 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The license agreements of most software companies try to keep users +at the mercy of those companies. By contrast, our General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. The +General Public License applies to the Free Software Foundation's +software and to any other program whose authors commit to using it. +You can use it for your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Specifically, the General Public License is designed to make +sure that you have the freedom to give away or sell copies of free +software, that you receive source code or can get it if you want it, +that you can change the software or use pieces of it in new free +programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of a such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must tell them their rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any program or other work which +contains a notice placed by the copyright holder saying it may be +distributed under the terms of this General Public License. The +"Program", below, refers to any such program or work, and a "work based +on the Program" means either the Program or any work containing the +Program or a portion of it, either verbatim or with modifications. Each +licensee is addressed as "you". + + 1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this +General Public License and to the absence of any warranty; and give any +other recipients of the Program a copy of this General Public License +along with the Program. You may charge a fee for the physical act of +transferring a copy. + + 2. You may modify your copy or copies of the Program or any portion of +it, and copy and distribute such modifications under the terms of Paragraph +1 above, provided that you also do the following: + + a) cause the modified files to carry prominent notices stating that + you changed the files and the date of any change; and + + b) cause the whole of any work that you distribute or publish, that + in whole or in part contains the Program or any part thereof, either + with or without modifications, to be licensed at no charge to all + third parties under the terms of this General Public License (except + that you may choose to grant warranty protection to some or all + third parties, at your option). + + c) If the modified program normally reads commands interactively when + run, you must cause it, when started running for such interactive use + in the simplest and most usual way, to print or display an + announcement including an appropriate copyright notice and a notice + that there is no warranty (or else, saying that you provide a + warranty) and that users may redistribute the program under these + conditions, and telling the user how to view a copy of this General + Public License. + + d) You may charge a fee for the physical act of transferring a + copy, and you may at your option offer warranty protection in + exchange for a fee. + +Mere aggregation of another independent work with the Program (or its +derivative) on a volume of a storage or distribution medium does not bring +the other work under the scope of these terms. + + 3. You may copy and distribute the Program (or a portion or derivative of +it, under Paragraph 2) in object code or executable form under the terms of +Paragraphs 1 and 2 above provided that you also do one of the following: + + a) accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of + Paragraphs 1 and 2 above; or, + + b) accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal charge + for the cost of distribution) a complete machine-readable copy of the + corresponding source code, to be distributed under the terms of + Paragraphs 1 and 2 above; or, + + c) accompany it with the information you received as to where the + corresponding source code may be obtained. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form alone.) + +Source code for a work means the preferred form of the work for making +modifications to it. For an executable file, complete source code means +all the source code for all modules it contains; but, as a special +exception, it need not include source code for modules which are standard +libraries that accompany the operating system on which the executable +file runs, or for standard header files or definitions files that +accompany that operating system. + + 4. You may not copy, modify, sublicense, distribute or transfer the +Program except as expressly provided under this General Public License. +Any attempt otherwise to copy, modify, sublicense, distribute or transfer +the Program is void, and will automatically terminate your rights to use +the Program under this License. However, parties who have received +copies, or rights to use copies, from you under this General Public +License will not have their licenses terminated so long as such parties +remain in full compliance. + + 5. By copying, distributing or modifying the Program (or any work based +on the Program) you indicate your acceptance of this license to do so, +and all its terms and conditions. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these +terms and conditions. You may not impose any further restrictions on the +recipients' exercise of the rights granted herein. + + 7. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of the license which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +the license, you may choose any version ever published by the Free Software +Foundation. + + 8. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to humanity, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + + To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19xx name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the +appropriate parts of the General Public License. Of course, the +commands you use may be called something other than `show w' and `show +c'; they could even be mouse-clicks or menu items--whatever suits your +program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + program `Gnomovision' (a program to direct compilers to make passes + at assemblers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +That's all there is to it! + + +--- The Artistic License 1.0 --- + +This software is Copyright (c) 2011 by Gisle Aas. + +This is free software, licensed under: + + The Artistic License 1.0 + +The Artistic License + +Preamble + +The intent of this document is to state the conditions under which a Package +may be copied, such that the Copyright Holder maintains some semblance of +artistic control over the development of the package, while giving the users of +the package the right to use and distribute the Package in a more-or-less +customary fashion, plus the right to make reasonable modifications. + +Definitions: + + - "Package" refers to the collection of files distributed by the Copyright + Holder, and derivatives of that collection of files created through + textual modification. + - "Standard Version" refers to such a Package if it has not been modified, + or has been modified in accordance with the wishes of the Copyright + Holder. + - "Copyright Holder" is whoever is named in the copyright or copyrights for + the package. + - "You" is you, if you're thinking about copying or distributing this Package. + - "Reasonable copying fee" is whatever you can justify on the basis of media + cost, duplication charges, time of people involved, and so on. (You will + not be required to justify it to the Copyright Holder, but only to the + computing community at large as a market that must bear the fee.) + - "Freely Available" means that no fee is charged for the item itself, though + there may be fees involved in handling the item. It also means that + recipients of the item may redistribute it under the same conditions they + received it. + +1. You may make and give away verbatim copies of the source form of the +Standard Version of this Package without restriction, provided that you +duplicate all of the original copyright notices and associated disclaimers. + +2. You may apply bug fixes, portability fixes and other modifications derived +from the Public Domain or from the Copyright Holder. A Package modified in such +a way shall still be considered the Standard Version. + +3. You may otherwise modify your copy of this Package in any way, provided that +you insert a prominent notice in each changed file stating how and when you +changed that file, and provided that you do at least ONE of the following: + + a) place your modifications in the Public Domain or otherwise make them + Freely Available, such as by posting said modifications to Usenet or an + equivalent medium, or placing the modifications on a major archive site + such as ftp.uu.net, or by allowing the Copyright Holder to include your + modifications in the Standard Version of the Package. + + b) use the modified Package only within your corporation or organization. + + c) rename any non-standard executables so the names do not conflict with + standard executables, which must also be provided, and provide a separate + manual page for each non-standard executable that clearly documents how it + differs from the Standard Version. + + d) make other distribution arrangements with the Copyright Holder. + +4. You may distribute the programs of this Package in object code or executable +form, provided that you do at least ONE of the following: + + a) distribute a Standard Version of the executables and library files, + together with instructions (in the manual page or equivalent) on where to + get the Standard Version. + + b) accompany the distribution with the machine-readable source of the Package + with your modifications. + + c) accompany any non-standard executables with their corresponding Standard + Version executables, giving the non-standard executables non-standard + names, and clearly documenting the differences in manual pages (or + equivalent), together with instructions on where to get the Standard + Version. + + d) make other distribution arrangements with the Copyright Holder. + +5. You may charge a reasonable copying fee for any distribution of this +Package. You may charge any fee you choose for support of this Package. You +may not charge a fee for this Package itself. However, you may distribute this +Package in aggregate with other (possibly commercial) programs as part of a +larger (possibly commercial) software distribution provided that you do not +advertise this Package as a product of your own. + +6. The scripts and library files supplied as input to or produced as output +from the programs of this Package do not automatically fall under the copyright +of this Package, but belong to whomever generated them, and may be sold +commercially, and may be aggregated with this Package. + +7. C or perl subroutines supplied by you and linked into this Package shall not +be considered part of this Package. + +8. The name of the Copyright Holder may not be used to endorse or promote +products derived from this software without specific prior written permission. + +9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +The End + diff --git a/MANIFEST b/MANIFEST index 6499ae8c..bc57631b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,6 +3,7 @@ lib/Net/HTTP.pm lib/Net/HTTP/Methods.pm lib/Net/HTTP/NB.pm lib/Net/HTTPS.pm +LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP From c36db3b969c1c23f051f51802c3758b13fe6002d Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:39:41 -0700 Subject: [PATCH 23/52] keep README and README.md refreshed --- Makefile.PL | 19 +++- README | 296 ++++++++++++++++++++++++---------------------------- 2 files changed, 156 insertions(+), 159 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 331269f7..6204d0d7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,7 +14,9 @@ else { unlink($flag_file); } -WriteMakefile( +my $developer = -f '.gitignore'; + +my %WriteMakefileArgs = ( NAME => 'Net::HTTP', VERSION_FROM => 'lib/Net/HTTP.pm', ABSTRACT_FROM => 'lib/Net/HTTP.pm', @@ -54,6 +56,21 @@ WriteMakefile( }, ); +WriteMakefile( + %WriteMakefileArgs, +); + +# pod2text is in https://metacpan.org/release/podlators +system("pod2text $WriteMakefileArgs{VERSION_FROM} > README") + if $developer + and (not -e 'README' or (stat('README'))[9] < (stat($WriteMakefileArgs{VERSION_FROM}))[9]); + +# pod2markdown is in https://metacpan.org/release/Pod-Markdown +system("pod2markdown $WriteMakefileArgs{VERSION_FROM} > README.md") + if $developer + and (not -e 'README.md' or (stat('README.md'))[9] < (stat($WriteMakefileArgs{VERSION_FROM}))[9]); + + BEGIN { # compatibility with older versions of MakeMaker diff --git a/README b/README index 45356c65..3029acd7 100644 --- a/README +++ b/README @@ -1,14 +1,12 @@ NAME - Net::HTTP - Low-level HTTP connection (client) SYNOPSIS - use Net::HTTP; my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); my($code, $mess, %h) = $s->read_response_headers; - + while (1) { my $buf; my $n = $s->read_entity_body($buf, 1024); @@ -18,223 +16,205 @@ SYNOPSIS } DESCRIPTION + The "Net::HTTP" class is a low-level HTTP client. An instance of the + "Net::HTTP" class represents a connection to an HTTP server. The HTTP + protocol is described in RFC 2616. The "Net::HTTP" class supports + "HTTP/1.0" and "HTTP/1.1". - The Net::HTTP class is a low-level HTTP client. An instance of the - Net::HTTP class represents a connection to an HTTP server. The HTTP - protocol is described in RFC 2616. The Net::HTTP class supports - HTTP/1.0 and HTTP/1.1. - - Net::HTTP is a sub-class of one of IO::Socket::IP (IPv6+IPv4), - IO::Socket::INET6 (IPv6+IPv4), or IO::Socket::INET (IPv4 only). You can - mix the methods described below with reading and writing from the - socket directly. This is not necessary a good idea, unless you know - what you are doing. + "Net::HTTP" is a sub-class of one of "IO::Socket::IP" (IPv6+IPv4), + "IO::Socket::INET6" (IPv6+IPv4), or "IO::Socket::INET" (IPv4 only). You + can mix the methods described below with reading and writing from the + socket directly. This is not necessary a good idea, unless you know what + you are doing. The following methods are provided (in addition to those of - IO::Socket::INET): + "IO::Socket::INET"): $s = Net::HTTP->new( %options ) - - The Net::HTTP constructor method takes the same options as - IO::Socket::INET's as well as these: - - Host: Initial host attribute value - KeepAlive: Initial keep_alive attribute value - SendTE: Initial send_te attribute_value - HTTPVersion: Initial http_version attribute value - PeerHTTPVersion: Initial peer_http_version attribute value - MaxLineLength: Initial max_line_length attribute value - MaxHeaderLines: Initial max_header_lines attribute value - - The Host option is also the default for IO::Socket::INET's PeerAddr. - The PeerPort defaults to 80 if not provided. The PeerPort - specification can also be embedded in the PeerAddr by preceding it - with a ":", and closing the IPv6 address on brackets "[]" if - necessary: "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". - - The Listen option provided by IO::Socket::INET's constructor method - is not allowed. - - If unable to connect to the given HTTP server then the constructor - returns undef and $@ contains the reason. After a successful connect, - a Net:HTTP object is returned. + The "Net::HTTP" constructor method takes the same options as + "IO::Socket::INET"'s as well as these: + + Host: Initial host attribute value + KeepAlive: Initial keep_alive attribute value + SendTE: Initial send_te attribute_value + HTTPVersion: Initial http_version attribute value + PeerHTTPVersion: Initial peer_http_version attribute value + MaxLineLength: Initial max_line_length attribute value + MaxHeaderLines: Initial max_header_lines attribute value + + The "Host" option is also the default for "IO::Socket::INET"'s + "PeerAddr". The "PeerPort" defaults to 80 if not provided. The + "PeerPort" specification can also be embedded in the "PeerAddr" by + preceding it with a ":", and closing the IPv6 address on brackets + "[]" if necessary: + "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". + + The "Listen" option provided by "IO::Socket::INET"'s constructor + method is not allowed. + + If unable to connect to the given HTTP server then the constructor + returns "undef" and $@ contains the reason. After a successful + connect, a "Net:HTTP" object is returned. $s->host - - Get/set the default value of the Host header to send. The $host must - not be set to an empty string (or undef) for HTTP/1.1. + Get/set the default value of the "Host" header to send. The $host + must not be set to an empty string (or "undef") for HTTP/1.1. $s->keep_alive + Get/set the *keep-alive* value. If this value is TRUE then the + request will be sent with headers indicating that the server should + try to keep the connection open so that multiple requests can be + sent. - Get/set the keep-alive value. If this value is TRUE then the request - will be sent with headers indicating that the server should try to - keep the connection open so that multiple requests can be sent. - - The actual headers set will depend on the value of the http_version - and peer_http_version attributes. + The actual headers set will depend on the value of the + "http_version" and "peer_http_version" attributes. $s->send_te - - Get/set the a value indicating if the request will be sent with a - "TE" header to indicate the transfer encodings that the server can - choose to use. The list of encodings announced as accepted by this - client depends on availability of the following modules: - Compress::Raw::Zlib for deflate, and IO::Compress::Gunzip for gzip. + Get/set the a value indicating if the request will be sent with a + "TE" header to indicate the transfer encodings that the server can + choose to use. The list of encodings announced as accepted by this + client depends on availability of the following modules: + "Compress::Raw::Zlib" for *deflate*, and "IO::Compress::Gunzip" for + *gzip*. $s->http_version - - Get/set the HTTP version number that this client should announce. - This value can only be set to "1.0" or "1.1". The default is "1.1". + Get/set the HTTP version number that this client should announce. + This value can only be set to "1.0" or "1.1". The default is "1.1". $s->peer_http_version - - Get/set the protocol version number of our peer. This value will - initially be "1.0", but will be updated by a successful - read_response_headers() method call. + Get/set the protocol version number of our peer. This value will + initially be "1.0", but will be updated by a successful + read_response_headers() method call. $s->max_line_length - - Get/set a limit on the length of response line and response header - lines. The default is 8192. A value of 0 means no limit. + Get/set a limit on the length of response line and response header + lines. The default is 8192. A value of 0 means no limit. $s->max_header_length - - Get/set a limit on the number of header lines that a response can - have. The default is 128. A value of 0 means no limit. + Get/set a limit on the number of header lines that a response can + have. The default is 128. A value of 0 means no limit. $s->format_request($method, $uri, %headers, [$content]) + Format a request message and return it as a string. If the headers + do not include a "Host" header, then a header is inserted with the + value of the "host" attribute. Headers like "Connection" and + "Keep-Alive" might also be added depending on the status of the + "keep_alive" attribute. - Format a request message and return it as a string. If the headers do - not include a Host header, then a header is inserted with the value - of the host attribute. Headers like Connection and Keep-Alive might - also be added depending on the status of the keep_alive attribute. - - If $content is given (and it is non-empty), then a Content-Length - header is automatically added unless it was already present. + If $content is given (and it is non-empty), then a "Content-Length" + header is automatically added unless it was already present. $s->write_request($method, $uri, %headers, [$content]) - - Format and send a request message. Arguments are the same as for - format_request(). Returns true if successful. + Format and send a request message. Arguments are the same as for + format_request(). Returns true if successful. $s->format_chunk( $data ) - - Returns the string to be written for the given chunk of data. + Returns the string to be written for the given chunk of data. $s->write_chunk($data) + Will write a new chunk of request entity body data. This method + should only be used if the "Transfer-Encoding" header with a value + of "chunked" was sent in the request. Note, writing zero-length data + is a no-op. Use the write_chunk_eof() method to signal end of entity + body data. - Will write a new chunk of request entity body data. This method - should only be used if the Transfer-Encoding header with a value of - chunked was sent in the request. Note, writing zero-length data is a - no-op. Use the write_chunk_eof() method to signal end of entity body - data. - - Returns true if successful. + Returns true if successful. $s->format_chunk_eof( %trailers ) - - Returns the string to be written for signaling EOF when a - Transfer-Encoding of chunked is used. + Returns the string to be written for signaling EOF when a + "Transfer-Encoding" of "chunked" is used. $s->write_chunk_eof( %trailers ) + Will write eof marker for chunked data and optional trailers. Note + that trailers should not really be used unless is was signaled with + a "Trailer" header. - Will write eof marker for chunked data and optional trailers. Note - that trailers should not really be used unless is was signaled with a - Trailer header. - - Returns true if successful. + Returns true if successful. ($code, $mess, %headers) = $s->read_response_headers( %opts ) - - Read response headers from server and return it. The $code is the 3 - digit HTTP status code (see HTTP::Status) and $mess is the textual - message that came with it. Headers are then returned as key/value - pairs. Since key letter casing is not normalized and the same key can - even occur multiple times, assigning these values directly to a hash - is not wise. Only the $code is returned if this method is called in - scalar context. - - As a side effect this method updates the 'peer_http_version' - attribute. - - Options might be passed in as key/value pairs. There are currently - only two options supported; laxed and junk_out. - - The laxed option will make read_response_headers() more forgiving - towards servers that have not learned how to speak HTTP properly. The - laxed option is a boolean flag, and is enabled by passing in a TRUE - value. The junk_out option can be used to capture bad header lines - when laxed is enabled. The value should be an array reference. Bad - header lines will be pushed onto the array. - - The laxed option must be specified in order to communicate with - pre-HTTP/1.0 servers that don't describe the response outcome or the - data they send back with a header block. For these servers - peer_http_version is set to "0.9" and this method returns (200, - "Assumed OK"). - - The method will raise an exception (die) if the server does not speak - proper HTTP or if the max_line_length or max_header_length limits are - reached. If the laxed option is turned on and max_line_length and - max_header_length checks are turned off, then no exception will be - raised and this method will always return a response code. + Read response headers from server and return it. The $code is the 3 + digit HTTP status code (see HTTP::Status) and $mess is the textual + message that came with it. Headers are then returned as key/value + pairs. Since key letter casing is not normalized and the same key + can even occur multiple times, assigning these values directly to a + hash is not wise. Only the $code is returned if this method is + called in scalar context. + + As a side effect this method updates the 'peer_http_version' + attribute. + + Options might be passed in as key/value pairs. There are currently + only two options supported; "laxed" and "junk_out". + + The "laxed" option will make read_response_headers() more forgiving + towards servers that have not learned how to speak HTTP properly. + The "laxed" option is a boolean flag, and is enabled by passing in a + TRUE value. The "junk_out" option can be used to capture bad header + lines when "laxed" is enabled. The value should be an array + reference. Bad header lines will be pushed onto the array. + + The "laxed" option must be specified in order to communicate with + pre-HTTP/1.0 servers that don't describe the response outcome or the + data they send back with a header block. For these servers + peer_http_version is set to "0.9" and this method returns (200, + "Assumed OK"). + + The method will raise an exception (die) if the server does not + speak proper HTTP or if the "max_line_length" or "max_header_length" + limits are reached. If the "laxed" option is turned on and + "max_line_length" and "max_header_length" checks are turned off, + then no exception will be raised and this method will always return + a response code. $n = $s->read_entity_body($buf, $size); + Reads chunks of the entity body content. Basically the same + interface as for read() and sysread(), but the buffer offset + argument is not supported yet. This method should only be called + after a successful read_response_headers() call. - Reads chunks of the entity body content. Basically the same interface - as for read() and sysread(), but the buffer offset argument is not - supported yet. This method should only be called after a successful - read_response_headers() call. + The return value will be "undef" on read errors, 0 on EOF, -1 if no + data could be returned this time, otherwise the number of bytes + assigned to $buf. The $buf is set to "" when the return value is -1. - The return value will be undef on read errors, 0 on EOF, -1 if no - data could be returned this time, otherwise the number of bytes - assigned to $buf. The $buf is set to "" when the return value is -1. + You normally want to retry this call if this function returns either + -1 or "undef" with $! as EINTR or EAGAIN (see Errno). EINTR can + happen if the application catches signals and EAGAIN can happen if + you made the socket non-blocking. - You normally want to retry this call if this function returns either - -1 or undef with $! as EINTR or EAGAIN (see Errno). EINTR can happen - if the application catches signals and EAGAIN can happen if you made - the socket non-blocking. - - This method will raise exceptions (die) if the server does not speak - proper HTTP. This can only happen when reading chunked data. + This method will raise exceptions (die) if the server does not speak + proper HTTP. This can only happen when reading chunked data. %headers = $s->get_trailers - - After read_entity_body() has returned 0 to indicate end of the entity - body, you might call this method to pick up any trailers. + After read_entity_body() has returned 0 to indicate end of the + entity body, you might call this method to pick up any trailers. $s->_rbuf - - Get/set the read buffer content. The read_response_headers() and - read_entity_body() methods use an internal buffer which they will - look for data before they actually sysread more from the socket - itself. If they read too much, the remaining data will be left in - this buffer. + Get/set the read buffer content. The read_response_headers() and + read_entity_body() methods use an internal buffer which they will + look for data before they actually sysread more from the socket + itself. If they read too much, the remaining data will be left in + this buffer. $s->_rbuf_length + Returns the number of bytes in the read buffer. This should always + be the same as: - Returns the number of bytes in the read buffer. This should always be - the same as: - - length($s->_rbuf) + length($s->_rbuf) - but might be more efficient. + but might be more efficient. SUBCLASSING - The read_response_headers() and read_entity_body() will invoke the sysread() method when they need more data. Subclasses might want to override this method to control how reading takes place. The object itself is a glob. Subclasses should avoid using hash key - names prefixed with http_ and io_. + names prefixed with "http_" and "io_". SEE ALSO - LWP, IO::Socket::INET, Net::HTTP::NB COPYRIGHT - Copyright 2001-2003 Gisle Aas. This library is free software; you can redistribute it and/or modify it From 4f1208e32e77896bb514ae31017657ba27850873 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:43:48 -0700 Subject: [PATCH 24/52] clean up build, being more respectful of really old EUMM --- Makefile.PL | 71 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 6204d0d7..3a8553ed 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,6 +15,7 @@ else { } my $developer = -f '.gitignore'; +ExtUtils::MakeMaker->VERSION(6.98) if $developer; my %WriteMakefileArgs = ( NAME => 'Net::HTTP', @@ -56,9 +57,49 @@ my %WriteMakefileArgs = ( }, ); -WriteMakefile( - %WriteMakefileArgs, -); +my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; + +for (qw(configure build test runtime)) { + my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; + next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_} + or exists $WriteMakefileArgs{$key}; + my $r = $WriteMakefileArgs{$key} = { + %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}}, + %{delete $WriteMakefileArgs{$key} || {}}, + }; + defined $r->{$_} or delete $r->{$_} for keys %$r; +} + +# dynamic prereqs get added here. + +$WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0; + +die 'attention developer: you need to do a sane meta merge here!' + if keys %{$WriteMakefileArgs{BUILD_REQUIRES}}; + +$WriteMakefileArgs{BUILD_REQUIRES} = { + %{$WriteMakefileArgs{BUILD_REQUIRES} || {}}, + %{delete $WriteMakefileArgs{TEST_REQUIRES}} +} if $eumm_version < 6.63_03; + +$WriteMakefileArgs{PREREQ_PM} = { + %{$WriteMakefileArgs{PREREQ_PM}}, + %{delete $WriteMakefileArgs{BUILD_REQUIRES}} +} if $eumm_version < 6.55_01; + +delete $WriteMakefileArgs{CONFIGURE_REQUIRES} + if $eumm_version < 6.51_03; + +delete $WriteMakefileArgs{MIN_PERL_VERSION} + if $eumm_version < 6.48; + +delete @WriteMakefileArgs{qw(META_ADD META_MERGE)} + if $eumm_version < 6.46; + +delete $WriteMakefileArgs{LICENSE} + if $eumm_version < 6.31; + +WriteMakefile(%WriteMakefileArgs); # pod2text is in https://metacpan.org/release/podlators system("pod2text $WriteMakefileArgs{VERSION_FROM} > README") @@ -69,27 +110,3 @@ system("pod2text $WriteMakefileArgs{VERSION_FROM} > README") system("pod2markdown $WriteMakefileArgs{VERSION_FROM} > README.md") if $developer and (not -e 'README.md' or (stat('README.md'))[9] < (stat($WriteMakefileArgs{VERSION_FROM}))[9]); - - - -BEGIN { - # compatibility with older versions of MakeMaker - my $developer = -f ".gitignore"; - my %mm_req = ( - LICENCE => 6.31, - META_MERGE => 6.45, - META_ADD => 6.45, - MIN_PERL_VERSION => 6.48, - ); - undef(*WriteMakefile); - *WriteMakefile = sub { - my %arg = @_; - for (keys %mm_req) { - unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) { - warn "$_ $@" if $developer; - delete $arg{$_}; - } - } - ExtUtils::MakeMaker::WriteMakefile(%arg); - }; -} From ff71fec41c9c3d53c2066c4aa06310f129d82721 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:52:48 -0700 Subject: [PATCH 25/52] use warnings everywhere, without enabling them globally for everything --- Changes | 3 ++- lib/Net/HTTP.pm | 1 + lib/Net/HTTP/Methods.pm | 1 + lib/Net/HTTP/NB.pm | 1 + lib/Net/HTTPS.pm | 1 + t/apache-https.t | 3 +-- t/apache.t | 3 +-- t/http-nb.t | 3 +-- t/http.t | 3 +-- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index 13386521..4a2bd4f2 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,9 @@ Release history for Net-HTTP -Karen Etheridge (1): +Karen Etheridge (2): Added LICENSE + Added 'use warnings' to everywhere that lacked it diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index 4d0f4500..0e3913cb 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -1,6 +1,7 @@ package Net::HTTP; use strict; +use warnings; use vars qw($VERSION @ISA $SOCKET_CLASS); $VERSION = "6.09"; diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 250d2509..2df68110 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -3,6 +3,7 @@ package Net::HTTP::Methods; require 5.005; # 4-arg substr use strict; +use warnings; use vars qw($VERSION); use URI; diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index d908cf8f..be6291c8 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -1,6 +1,7 @@ package Net::HTTP::NB; use strict; +use warnings; use vars qw($VERSION @ISA); $VERSION = "6.09"; diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 96dd288e..032dc8eb 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -1,6 +1,7 @@ package Net::HTTPS; use strict; +use warnings; use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); $VERSION = "6.09"; diff --git a/t/apache-https.t b/t/apache-https.t index d7e54fd0..5d89f9f1 100644 --- a/t/apache-https.t +++ b/t/apache-https.t @@ -1,5 +1,3 @@ -#!perl -w - BEGIN { unless (-f "t/LIVE_TESTS" || -f "LIVE_TESTS") { print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; @@ -27,6 +25,7 @@ BEGIN { } use strict; +use warnings; use Test; plan tests => 8; diff --git a/t/apache.t b/t/apache.t index 83f9faff..c11ea1f3 100644 --- a/t/apache.t +++ b/t/apache.t @@ -1,5 +1,3 @@ -#!perl -w - BEGIN { unless (-f "t/LIVE_TESTS" || -f "LIVE_TESTS") { print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; @@ -21,6 +19,7 @@ BEGIN { } use strict; +use warnings; use Test; plan tests => 8; diff --git a/t/http-nb.t b/t/http-nb.t index d5c0341c..0c7b187c 100644 --- a/t/http-nb.t +++ b/t/http-nb.t @@ -1,6 +1,5 @@ -#!perl -w - use strict; +use warnings; use Test::More; plan skip_all => "This test doesn't work on Windows" if $^O eq "MSWin32"; diff --git a/t/http.t b/t/http.t index cc2e1d3b..12d59ac9 100644 --- a/t/http.t +++ b/t/http.t @@ -1,6 +1,5 @@ -#!perl -w - use strict; +use warnings; use Test; plan tests => 37; From 400561d4dfce1d46c72c037667cb06083dd5b53c Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:53:03 -0700 Subject: [PATCH 26/52] tighten up entries --- .gitignore | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3c50b513..188b4582 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ -Makefile -Makefile.old -blib -pm_to_blib +/Makefile +/Makefile.old +/blib/ +/pm_to_blib SSL t/CAN_TALK_TO_OURSELF t/live/ENABLED -*.tar.gz xx* /_eumm/ /MYMETA.* From a9788eb5577a82c67aae30592db60d5a4e2a3e42 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:56:39 -0700 Subject: [PATCH 27/52] refactor off of Test.pm --- Changes | 3 ++- t/apache-https.t | 10 +++---- t/apache.t | 10 +++---- t/http.t | 70 ++++++++++++++++++++++++------------------------ 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/Changes b/Changes index 4a2bd4f2..79a81a2c 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,10 @@ Release history for Net-HTTP -Karen Etheridge (2): +Karen Etheridge (3): Added LICENSE Added 'use warnings' to everywhere that lacked it + Drop all use of Test.pm diff --git a/t/apache-https.t b/t/apache-https.t index 5d89f9f1..b5514c59 100644 --- a/t/apache-https.t +++ b/t/apache-https.t @@ -26,7 +26,7 @@ BEGIN { use strict; use warnings; -use Test; +use Test::More; plan tests => 8; use Net::HTTPS; @@ -63,10 +63,10 @@ for (1..2) { (my $out = $buf) =~ s/^/# /gm; print $out; - ok($code, "200"); - ok($h{'Content-Type'}, "message/http"); + is($code, "200"); + is($h{'Content-Type'}, "message/http"); - ok($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - ok($buf, qr/^User-Agent: Mozilla\/5.0$/m); + is($buf, qr/^TRACE \/libwww-perl HTTP\/1/); + is($buf, qr/^User-Agent: Mozilla\/5.0$/m); } diff --git a/t/apache.t b/t/apache.t index c11ea1f3..c3b2926f 100644 --- a/t/apache.t +++ b/t/apache.t @@ -20,7 +20,7 @@ BEGIN { use strict; use warnings; -use Test; +use Test::More; plan tests => 8; use Net::HTTP; @@ -57,10 +57,10 @@ for (1..2) { (my $out = $buf) =~ s/^/# /gm; print $out; - ok($code, "200"); - ok($h{'Content-Type'}, "message/http"); + is($code, "200"); + is($h{'Content-Type'}, "message/http"); - ok($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - ok($buf, qr/^User-Agent: Mozilla\/5.0$/m); + is($buf, qr/^TRACE \/libwww-perl HTTP\/1/); + is($buf, qr/^User-Agent: Mozilla\/5.0$/m); } diff --git a/t/http.t b/t/http.t index 12d59ac9..a8c44abd 100644 --- a/t/http.t +++ b/t/http.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test; +use Test::More; plan tests => 37; #use Data::Dump (); @@ -120,84 +120,84 @@ $res = $h->request(GET => "/"); #Data::Dump::dump($res); -ok($res->{code}, 200); -ok($res->{content}, "Hello\n"); +is($res->{code}, 200); +is($res->{content}, "Hello\n"); $res = $h->request(GET => "/404"); -ok($res->{code}, 404); +is($res->{code}, 404); $res = $h->request(TRACE => "/foo"); -ok($res->{code}, 200); -ok($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Keep-Alive: 300${CRLF}Connection: Keep-Alive${CRLF}Host: a${CRLF}${CRLF}"); +is($res->{code}, 200); +is($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Keep-Alive: 300${CRLF}Connection: Keep-Alive${CRLF}Host: a${CRLF}${CRLF}"); # try to turn off keep alive $h->keep_alive(0); $res = $h->request(TRACE => "/foo"); -ok($res->{code}, "200"); -ok($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Connection: close${CRLF}Host: a${CRLF}${CRLF}"); +is($res->{code}, "200"); +is($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Connection: close${CRLF}Host: a${CRLF}${CRLF}"); # try a bad one # It's bad because 2nd 'HTTP/1.0 200' is illegal. But passes anyway if laxed => 1. $res = $h->request(GET => "/bad1", [], {laxed => 1}); -ok($res->{code}, "200"); -ok($res->{message}, "OK"); -ok("@{$res->{headers}}", "Server foo Content-type text/foo"); -ok($res->{content}, "abc\n"); +is($res->{code}, "200"); +is($res->{message}, "OK"); +is("@{$res->{headers}}", "Server foo Content-type text/foo"); +is($res->{content}, "abc\n"); $res = $h->request(GET => "/bad1"); -ok($res->{error} =~ /Bad header/); +like($res->{error}, qr/Bad header/); ok(!$res->{code}); $h = undef; # it is in a bad state now $h = HTTP->new("a") || die; # reconnect $res = $h->request(GET => "/09", [], {laxed => 1}); -ok($res->{code}, "200"); -ok($res->{message}, "Assumed OK"); -ok($res->{content}, "Hello${CRLF}World!${CRLF}"); -ok($h->peer_http_version, "0.9"); +is($res->{code}, "200"); +is($res->{message}, "Assumed OK"); +is($res->{content}, "Hello${CRLF}World!${CRLF}"); +is($h->peer_http_version, "0.9"); $res = $h->request(GET => "/09"); -ok($res->{error} =~ /^Bad response status line: 'Hello'/); +like($res->{error}, qr/^Bad response status line: 'Hello'/); $h = undef; # it's in a bad state again $h = HTTP->new(Host => "a", KeepAlive => 1, ReadChunkSize => 1) || die; # reconnect $res = $h->request(GET => "/chunked"); -ok($res->{code}, 200); -ok($res->{content}, "Hello"); -ok("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx"); +is($res->{code}, 200); +is($res->{content}, "Hello"); +is("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx"); # once more $res = $h->request(GET => "/chunked"); -ok($res->{code}, "200"); -ok($res->{content}, "Hello"); -ok("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx"); +is($res->{code}, "200"); +is($res->{content}, "Hello"); +is("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx"); # Test bogus headers. Chunked appearing twice is illegal, but happens anyway sometimes. [RT#77240] $res = $h->request(GET => "/chunked,chunked"); -ok($res->{code}, "200"); -ok($res->{content}, "Hello"); -ok("@{$res->{headers}}", "Transfer-Encoding chunked Transfer-Encoding chunked Content-MD5 xxx"); +is($res->{code}, "200"); +is($res->{content}, "Hello"); +is("@{$res->{headers}}", "Transfer-Encoding chunked Transfer-Encoding chunked Content-MD5 xxx"); # test head $res = $h->request(HEAD => "/head"); -ok($res->{code}, "200"); -ok($res->{content}, ""); -ok("@{$res->{headers}}", "Content-Length 16 Content-Type text/plain"); +is($res->{code}, "200"); +is($res->{content}, ""); +is("@{$res->{headers}}", "Content-Length 16 Content-Type text/plain"); $res = $h->request(GET => "/"); -ok($res->{code}, "200"); -ok($res->{content}, "Hello\n"); +is($res->{code}, "200"); +is($res->{content}, "Hello\n"); $h = HTTP->new(Host => undef, PeerAddr => "a", ); $h->http_version("1.0"); ok(!defined $h->host); $res = $h->request(TRACE => "/"); -ok($res->{code}, "200"); -ok($res->{content}, "TRACE / HTTP/1.0\r\n\r\n"); +is($res->{code}, "200"); +is($res->{content}, "TRACE / HTTP/1.0\r\n\r\n"); # check that headers with colons at the start of values don't break $res = $h->request(GET => '/colon-header'); -ok("@{$res->{headers}}", "Content-Type text/plain Content-Length 6 Bad-Header :foo"); +is("@{$res->{headers}}", "Content-Type text/plain Content-Length 6 Bad-Header :foo"); require Net::HTTP; eval { From 57a0948bc1e0eb679a81e71e2aeb810706a331df Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Sun, 28 Jun 2015 17:59:56 -0700 Subject: [PATCH 28/52] remove unneeded uses of "use vars", keepign $SOCKET_CLASS overridable --- Changes | 3 ++- lib/Net/HTTP.pm | 6 +++--- lib/Net/HTTP/Methods.pm | 5 +---- lib/Net/HTTP/NB.pm | 6 ++---- lib/Net/HTTPS.pm | 6 +++--- t/http.t | 4 +--- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Changes b/Changes index 79a81a2c..2e4f7af0 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,11 @@ Release history for Net-HTTP -Karen Etheridge (3): +Karen Etheridge (4): Added LICENSE Added 'use warnings' to everywhere that lacked it Drop all use of Test.pm + Removed unneeded uses of 'use vars' diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index 0e3913cb..cba27452 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -2,11 +2,11 @@ package Net::HTTP; use strict; use warnings; -use vars qw($VERSION @ISA $SOCKET_CLASS); -$VERSION = "6.09"; +our $VERSION = "6.09"; $VERSION = eval $VERSION; +use vars qw($SOCKET_CLASS); unless ($SOCKET_CLASS) { # Try several, in order of capability and preference if (eval { require IO::Socket::IP }) { @@ -23,7 +23,7 @@ unless ($SOCKET_CLASS) { require Net::HTTP::Methods; require Carp; -@ISA = ($SOCKET_CLASS, 'Net::HTTP::Methods'); +our @ISA = ($SOCKET_CLASS, 'Net::HTTP::Methods'); sub new { my $class = shift; diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 2df68110..97fb06cc 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -1,13 +1,10 @@ package Net::HTTP::Methods; -require 5.005; # 4-arg substr - use strict; use warnings; -use vars qw($VERSION); use URI; -$VERSION = "6.09"; +our $VERSION = "6.09"; $VERSION = eval $VERSION; my $CRLF = "\015\012"; # "\r\n" is not portable diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index be6291c8..fb72740f 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -2,13 +2,11 @@ package Net::HTTP::NB; use strict; use warnings; -use vars qw($VERSION @ISA); -$VERSION = "6.09"; +our $VERSION = "6.09"; $VERSION = eval $VERSION; -require Net::HTTP; -@ISA=qw(Net::HTTP); +use base 'Net::HTTP'; sub can_read { return 1; diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 032dc8eb..06e38179 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -2,12 +2,12 @@ package Net::HTTPS; use strict; use warnings; -use vars qw($VERSION $SSL_SOCKET_CLASS @ISA); -$VERSION = "6.09"; +our $VERSION = "6.09"; $VERSION = eval $VERSION; # Figure out which SSL implementation to use +use vars qw($SSL_SOCKET_CLASS); if ($SSL_SOCKET_CLASS) { # somebody already set it } @@ -44,7 +44,7 @@ else { require Net::HTTP::Methods; -@ISA=($SSL_SOCKET_CLASS, 'Net::HTTP::Methods'); +our @ISA=($SSL_SOCKET_CLASS, 'Net::HTTP::Methods'); sub configure { my($self, $cnf) = @_; diff --git a/t/http.t b/t/http.t index a8c44abd..358f15d5 100644 --- a/t/http.t +++ b/t/http.t @@ -10,9 +10,7 @@ my $LF = "\012"; { package HTTP; - use vars qw(@ISA); - require Net::HTTP::Methods; - @ISA=qw(Net::HTTP::Methods); + use base 'Net::HTTP::Methods'; my %servers = ( a => { "/" => "HTTP/1.0 200 OK${CRLF}Content-Type: text/plain${CRLF}Content-Length: 6${CRLF}${CRLF}Hello\n", From 86eeb81a078391316614dac8569e5e124f3a86e6 Mon Sep 17 00:00:00 2001 From: Lasse Makholm Date: Fri, 11 Mar 2016 23:49:36 +0100 Subject: [PATCH 29/52] use like() instead of is() for regex checking responses --- t/apache-https.t | 4 ++-- t/apache.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/t/apache-https.t b/t/apache-https.t index b5514c59..8a25df92 100644 --- a/t/apache-https.t +++ b/t/apache-https.t @@ -66,7 +66,7 @@ for (1..2) { is($code, "200"); is($h{'Content-Type'}, "message/http"); - is($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - is($buf, qr/^User-Agent: Mozilla\/5.0$/m); + like($buf, qr/^TRACE \/libwww-perl HTTP\/1/); + like($buf, qr/^User-Agent: Mozilla\/5.0$/m); } diff --git a/t/apache.t b/t/apache.t index c3b2926f..91953852 100644 --- a/t/apache.t +++ b/t/apache.t @@ -60,7 +60,7 @@ for (1..2) { is($code, "200"); is($h{'Content-Type'}, "message/http"); - is($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - is($buf, qr/^User-Agent: Mozilla\/5.0$/m); + like($buf, qr/^TRACE \/libwww-perl HTTP\/1/); + like($buf, qr/^User-Agent: Mozilla\/5.0$/m); } From bb40f23a4fdfd38c9844d49fca915313afc5211f Mon Sep 17 00:00:00 2001 From: Lasse Makholm Date: Sat, 12 Mar 2016 00:12:33 +0100 Subject: [PATCH 30/52] Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0 my_readline() is broken for response sizes (headers + raw body) that are multiples of 1024 (sysread block size). When reading from date from the socket, we keep reading until we get fewer bytes than we asked for. The code implicitly assumes that if we're getting *exactly* what we asked for, then there is more data available. That assumption does not hold true for response sizes of 1024, 2048, etc... In most cases, this bug is masked by either not using keep-alive or by a lot of servers having short keep-alive timeouts. It is easily reproducible though by using a simple Plack one-liner and tweaking the response size until hitting e.g. 1024 bytes in the first sysread(). The following works with starman: $ cat foo.psgi sub { [ 200, [], [ "x" x 904 ] ] } # Tweak response size as needed, depending on headers sent by starman $ $ starman --keepalive-timeout 10 foo.psgi Elsewhere, run: $ time perl -MLWP::UserAgent -e 'print LWP::UserAgent->new(keep_alive => 1)->post(q(http://127.0.0.1:5000))->status_line' 200 OK real 0m10.067s user 0m0.052s sys 0m0.004s $ Net::HTTP hangs, waiting for more data until the server disconnects. The simplest fix seems to be just checking can_read() before another read if we get exactly what we asked for in sysread(). --- lib/Net/HTTP/Methods.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 97fb06cc..4f4249c7 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -277,6 +277,8 @@ sub my_readline { if(defined $bytes_read) { $new_bytes += $bytes_read; last if $bytes_read < 1024; + # We got exactly 1024 bytes, so we need to select() to know if there is more data + last unless $self->can_read(0); } elsif($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) { redo READ; From 31289a37fada8917ab317cb25e5fcd23b50519f5 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 30 Jun 2016 06:45:37 -0400 Subject: [PATCH 31/52] Add .travis.yml --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..365f9a50 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: perl +perl: + - "5.24" + - "5.22" + - "5.20" + - "5.18" + - "5.16" + - "5.14" + - "5.12" + - "5.10" +before_install: + - git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers + - source ~/travis-perl-helpers/init + - build-perl + - perl -V From 4a3d24de31e17201b7a07f9e17a852600174ded1 Mon Sep 17 00:00:00 2001 From: Andy Grundman Date: Fri, 12 Aug 2016 14:25:29 -0400 Subject: [PATCH 32/52] Change the live HTTP(S) tests to use GET at google.com instead of TRACE at apache.org. Apache recently changed their server config and no longer allow TRACE requests. --- MANIFEST | 4 +-- t/apache-https.t | 72 ---------------------------------------------- t/apache.t | 66 ------------------------------------------ t/live-https.t | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ t/live.t | 68 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+), 140 deletions(-) delete mode 100644 t/apache-https.t delete mode 100644 t/apache.t create mode 100644 t/live-https.t create mode 100644 t/live.t diff --git a/MANIFEST b/MANIFEST index bc57631b..2a781ea9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,7 +8,7 @@ Makefile.PL MANIFEST This list of files MANIFEST.SKIP README -t/apache-https.t -t/apache.t +t/live-https.t +t/live.t t/http-nb.t t/http.t diff --git a/t/apache-https.t b/t/apache-https.t deleted file mode 100644 index 8a25df92..00000000 --- a/t/apache-https.t +++ /dev/null @@ -1,72 +0,0 @@ -BEGIN { - unless (-f "t/LIVE_TESTS" || -f "LIVE_TESTS") { - print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; - exit; - } - eval { - require IO::Socket::INET; - my $s = IO::Socket::INET->new( - PeerHost => "www.apache.org:443", - Timeout => 5, - ); - die "Can't connect: $@" unless $s; - }; - if ($@) { - print "1..0 # SKIP Can't connect to www.apache.org\n"; - print $@; - exit; - } - - unless (eval { require IO::Socket::SSL} || eval { require Net::SSL }) { - print "1..0 # SKIP IO::Socket::SSL or Net::SSL not available\n"; - print $@; - exit; - } -} - -use strict; -use warnings; -use Test::More; -plan tests => 8; - -use Net::HTTPS; - - -my $s = Net::HTTPS->new(Host => "www.apache.org", - KeepAlive => 1, - Timeout => 15, - PeerHTTPVersion => "1.1", - MaxLineLength => 512) || die "$@"; - -for (1..2) { - $s->write_request(TRACE => "/libwww-perl", - 'User-Agent' => 'Mozilla/5.0', - 'Accept-Language' => 'no,en', - Accept => '*/*'); - - my($code, $mess, %h) = $s->read_response_headers; - print "# ----------------------------\n"; - print "# $code $mess\n"; - for (sort keys %h) { - print "# $_: $h{$_}\n"; - } - print "#\n"; - - my $buf; - while (1) { - my $tmp; - my $n = $s->read_entity_body($tmp, 20); - last unless $n; - $buf .= $tmp; - } - $buf =~ s/\r//g; - (my $out = $buf) =~ s/^/# /gm; - print $out; - - is($code, "200"); - is($h{'Content-Type'}, "message/http"); - - like($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - like($buf, qr/^User-Agent: Mozilla\/5.0$/m); -} - diff --git a/t/apache.t b/t/apache.t deleted file mode 100644 index 91953852..00000000 --- a/t/apache.t +++ /dev/null @@ -1,66 +0,0 @@ -BEGIN { - unless (-f "t/LIVE_TESTS" || -f "LIVE_TESTS") { - print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; - exit; - } - eval { - require IO::Socket::INET; - my $s = IO::Socket::INET->new( - PeerHost => "www.apache.org:80", - Timeout => 5, - ); - die "Can't connect: $@" unless $s; - }; - if ($@) { - print "1..0 # SKIP Can't connect to www.apache.org\n"; - print $@; - exit; - } -} - -use strict; -use warnings; -use Test::More; -plan tests => 8; - -use Net::HTTP; - - -my $s = Net::HTTP->new(Host => "www.apache.org", - KeepAlive => 1, - Timeout => 15, - PeerHTTPVersion => "1.1", - MaxLineLength => 512) || die "$@"; - -for (1..2) { - $s->write_request(TRACE => "/libwww-perl", - 'User-Agent' => 'Mozilla/5.0', - 'Accept-Language' => 'no,en', - Accept => '*/*'); - - my($code, $mess, %h) = $s->read_response_headers; - print "# ----------------------------\n"; - print "# $code $mess\n"; - for (sort keys %h) { - print "# $_: $h{$_}\n"; - } - print "#\n"; - - my $buf; - while (1) { - my $tmp; - my $n = $s->read_entity_body($tmp, 20); - last unless $n; - $buf .= $tmp; - } - $buf =~ s/\r//g; - (my $out = $buf) =~ s/^/# /gm; - print $out; - - is($code, "200"); - is($h{'Content-Type'}, "message/http"); - - like($buf, qr/^TRACE \/libwww-perl HTTP\/1/); - like($buf, qr/^User-Agent: Mozilla\/5.0$/m); -} - diff --git a/t/live-https.t b/t/live-https.t new file mode 100644 index 00000000..3482bbf4 --- /dev/null +++ b/t/live-https.t @@ -0,0 +1,74 @@ +BEGIN { + unless ( -f "t/LIVE_TESTS" || -f "LIVE_TESTS" ) { + print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; + exit; + } + eval { + require IO::Socket::INET; + my $s = IO::Socket::INET->new( + PeerHost => "www.google.com:443", + Timeout => 5, + ); + die "Can't connect: $@" unless $s; + }; + if ($@) { + print "1..0 # SKIP Can't connect to www.google.com:443\n"; + print $@; + exit; + } + + unless ( eval { require IO::Socket::SSL } || eval { require Net::SSL } ) { + print "1..0 # SKIP IO::Socket::SSL or Net::SSL not available\n"; + print $@; + exit; + } +} + +use strict; +use warnings; +use Test::More; +plan tests => 6; + +use Net::HTTPS; + +my $s = Net::HTTPS->new( + Host => "www.google.com", + KeepAlive => 1, + Timeout => 15, + PeerHTTPVersion => "1.1", + MaxLineLength => 512 +) || die "$@"; + +for ( 1 .. 2 ) { + $s->write_request( + GET => "/", + 'User-Agent' => 'Mozilla/5.0', + 'Accept-Language' => 'no,en', + Accept => '*/*' + ); + + my ( $code, $mess, %h ) = $s->read_response_headers; + print "# ----------------------------\n"; + print "# $code $mess\n"; + for ( sort keys %h ) { + print "# $_: $h{$_}\n"; + } + print "#\n"; + + my $buf; + while (1) { + my $tmp; + my $n = $s->read_entity_body( $tmp, 20 ); + last unless $n; + $buf .= $tmp; + } + $buf =~ s/\r//g; + + # ( my $out = $buf ) =~ s/^/# /gm; + # print $out; + + is( $code, "200" ); + like( $h{'Content-Type'}, qr{text/html} ); + like( $buf, qr{} ); +} + diff --git a/t/live.t b/t/live.t new file mode 100644 index 00000000..747515a9 --- /dev/null +++ b/t/live.t @@ -0,0 +1,68 @@ +BEGIN { + unless ( -f "t/LIVE_TESTS" || -f "LIVE_TESTS" ) { + print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; + exit; + } + eval { + require IO::Socket::INET; + my $s = IO::Socket::INET->new( + PeerHost => "www.google.com:80", + Timeout => 5, + ); + die "Can't connect: $@" unless $s; + }; + if ($@) { + print "1..0 # SKIP Can't connect to www.google.com\n"; + print $@; + exit; + } +} + +use strict; +use warnings; +use Test::More; +plan tests => 6; + +use Net::HTTP; + +my $s = Net::HTTP->new( + Host => "www.google.com", + KeepAlive => 1, + Timeout => 15, + PeerHTTPVersion => "1.1", + MaxLineLength => 512 +) || die "$@"; + +for ( 1 .. 2 ) { + $s->write_request( + GET => "/", + 'User-Agent' => 'Mozilla/5.0', + 'Accept-Language' => 'no,en', + Accept => '*/*' + ); + + my ( $code, $mess, %h ) = $s->read_response_headers; + print "# ----------------------------\n"; + print "# $code $mess\n"; + for ( sort keys %h ) { + print "# $_: $h{$_}\n"; + } + print "#\n"; + + my $buf; + while (1) { + my $tmp; + my $n = $s->read_entity_body( $tmp, 20 ); + last unless $n; + $buf .= $tmp; + } + $buf =~ s/\r//g; + + # ( my $out = $buf ) =~ s/^/# /gm; + # print $out; + + is( $code, "200" ); + like( $h{'Content-Type'}, qr{text/html} ); + like( $buf, qr{} ); +} + From 98941ec30b8fe8ce261b2499d62f37930363ccf7 Mon Sep 17 00:00:00 2001 From: Lasse Makholm Date: Thu, 29 Dec 2016 12:51:27 +0100 Subject: [PATCH 33/52] Add test to verify fix for RT#112313 Test against http://httpbin.org/headers and iterate until responses are exactly 1024, 2048 or 3072 bytes in size. --- t/rt-112313.t | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 t/rt-112313.t diff --git a/t/rt-112313.t b/t/rt-112313.t new file mode 100644 index 00000000..365d4988 --- /dev/null +++ b/t/rt-112313.t @@ -0,0 +1,95 @@ +use strict; +use warnings; +use Test::More; +use Net::HTTP; + +# Attempt to verify that RT#112313 (Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0) is fixed + +# To do that, we need responses (headers + body) that are even multiples of 1024 bytes. So we +# iterate over the same URL, trying to grow the response size incrementally... + +# There's a chance this test won't work if, for example, the response body grows by one byte while +# the Content-Length also rolls over to one more digit, thus increasing the total response by two +# bytes. + +# So, we check that the reponse growth is only one byte after each iteration and also test multiple +# times across the 1024, 2048 and 3072 boundaries... + +unless (-f "t/LIVE_TESTS" || -f "LIVE_TESTS") +{ + print "1..0 # SKIP Live tests disabled; pass --live-tests to Makefile.PL to enable\n"; + exit; +} + +sub try +{ + my $n = shift; + + # Need a new socket every time because we're testing with Keep-Alive... + my $s = Net::HTTP->new( + Host => "httpbin.org", + KeepAlive => 1, + PeerHTTPVersion => "1.1", + ) or die "$@"; + + $s->write_request(GET => '/headers', + 'User-Agent' => "Net::HTTP - $0", + 'X-Foo' => ('x' x $n), + ); + + # Wait until all data is probably available on the socket... + sleep 1; + + my ($code, $mess, @headers) = $s->read_response_headers(); + + my $body = ''; + while ($s->read_entity_body(my $buf, 1024)) + { + $body .= $buf; + } + + # Compute what is probably the total response length... + my $total_len = length(join "\r\n", 'HTTP/1.1', "$code $mess", @headers, '', $body) - 1; + + # diag("$n - $code $mess => $total_len"); + # diag(join "\r\n", 'HTTP/1.1', "$code $mess", @headers, '', $body); + + $code == 200 + or die "$code $mess"; + + return $total_len; +} + +my $timeout = 15; +my $wiggle_room = 3; + +local $SIG{ALRM} = sub { die 'timeout' }; + +my $base_len = try(1); +ok($base_len < 1024, "base response length is less than 1024: $base_len"); + +for my $kb (1024, 2048, 3072) +{ + my $last; + + # Calculate range that will take us across the 1024 boundary... + for my $n (($kb - $base_len - $wiggle_room) .. ($kb - $base_len + $wiggle_room)) + { + my $len = -1; + + eval { + alarm $timeout; + $len = try($n); + }; + + ok(!$@, "ok for n $n -> response length $len") + or diag("error: $@"); + + # Verify that response length only increased by one since the whole test rests on that assumption... + is($len - $last, 1, 'reponse length increased by 1') if $last; + + $last = $len; + } +} + +done_testing(); From 67388cd09efd72138ff449fb2251968ccbb502f2 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Tue, 8 Nov 2016 20:49:23 -0500 Subject: [PATCH 34/52] Convert to dzil. --- Install | 43 ++++++++ LICENSE | 6 +- MANIFEST | 14 --- MANIFEST.SKIP | 6 -- META.json | 146 ++++++++++++++++++++++++++ Makefile.PL | 165 ++++++++++++----------------- README | 222 ---------------------------------------- README.md | 23 ++++- cpanfile | 35 +++++++ dist.ini | 23 +++++ lib/Net/HTTP.pm | 3 - lib/Net/HTTP/Methods.pm | 3 - lib/Net/HTTP/NB.pm | 3 - lib/Net/HTTPS.pm | 3 - perlcriticrc | 86 ++++++++++++++++ perltidyrc | 12 +++ tidyall.ini | 19 ++++ 17 files changed, 456 insertions(+), 356 deletions(-) create mode 100644 Install delete mode 100644 MANIFEST delete mode 100644 MANIFEST.SKIP create mode 100644 META.json delete mode 100644 README create mode 100644 cpanfile create mode 100644 dist.ini create mode 100644 perlcriticrc create mode 100644 perltidyrc create mode 100644 tidyall.ini diff --git a/Install b/Install new file mode 100644 index 00000000..457aa220 --- /dev/null +++ b/Install @@ -0,0 +1,43 @@ +This is the Perl distribution Net-HTTP. + +Installing Net-HTTP is straightforward. + +## Installation with cpanm + +If you have cpanm, you only need one line: + + % cpanm Net::HTTP + +If you are installing into a system-wide directory, you may need to pass the +"-S" flag to cpanm, which uses sudo to install the module: + + % cpanm -S Net::HTTP + +## Installing with the CPAN shell + +Alternatively, if your CPAN shell is set up, you should just be able to do: + + % cpan Net::HTTP + +## Manual installation + +As a last resort, you can manually install it. Download the tarball, untar it, +then build it: + + % perl Makefile.PL + % make && make test + +Then install it: + + % make install + +If you are installing into a system-wide directory, you may need to run: + + % sudo make install + +## Documentation + +Net-HTTP documentation is available as POD. +You can run perldoc from a shell to read the documentation: + + % perldoc Net::HTTP diff --git a/LICENSE b/LICENSE index deecb6d9..a7d6970b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -This software is copyright (c) 2011 by Gisle Aas. +This software is copyright (c) 2001-2016 by Gisle Aas. 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) 2011 by Gisle Aas. +This software is Copyright (c) 2001-2016 by Gisle Aas. 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) 2011 by Gisle Aas. +This software is Copyright (c) 2001-2016 by Gisle Aas. This is free software, licensed under: diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 2a781ea9..00000000 --- a/MANIFEST +++ /dev/null @@ -1,14 +0,0 @@ -Changes -lib/Net/HTTP.pm -lib/Net/HTTP/Methods.pm -lib/Net/HTTP/NB.pm -lib/Net/HTTPS.pm -LICENSE -Makefile.PL -MANIFEST This list of files -MANIFEST.SKIP -README -t/live-https.t -t/live.t -t/http-nb.t -t/http.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP deleted file mode 100644 index add4a7a3..00000000 --- a/MANIFEST.SKIP +++ /dev/null @@ -1,6 +0,0 @@ -#!include_default - -\.ackrc -Net-HTTP-.*/ -Net-HTTP-.*.tar.gz -README.md diff --git a/META.json b/META.json new file mode 100644 index 00000000..0ee2e580 --- /dev/null +++ b/META.json @@ -0,0 +1,146 @@ +{ + "abstract" : "Low-level HTTP connection (client)", + "author" : [ + "Gisle Aas " + ], + "dynamic_config" : 0, + "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150005", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : 2 + }, + "name" : "Net-HTTP", + "no_index" : { + "directory" : [ + "examples", + "t", + "xt" + ] + }, + "prereqs" : { + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + }, + "suggests" : { + "JSON::PP" : "2.27300" + } + }, + "develop" : { + "requires" : { + "Test::CPAN::Changes" : "0.19" + } + }, + "runtime" : { + "requires" : { + "Carp" : "0", + "Compress::Raw::Zlib" : "0", + "IO::Socket" : "0", + "IO::Socket::INET" : "0", + "IO::Socket::INET6" : "0", + "IO::Socket::IP" : "0", + "IO::Socket::SSL" : "0", + "IO::Uncompress::Gunzip" : "0", + "Net::SSL" : "0", + "Symbol" : "0", + "URI" : "0", + "base" : "0", + "perl" : "5.006002", + "strict" : "0", + "vars" : "0", + "warnings" : "0" + } + }, + "test" : { + "requires" : { + "Data::Dumper" : "0", + "IO::Select" : "0", + "Socket" : "0", + "Test::More" : "0" + } + } + }, + "release_status" : "stable", + "resources" : { + "bugtracker" : { + "web" : "https://github.com/libwww-perl/Net-HTTP/issues" + }, + "homepage" : "https://github.com/libwww-perl/Net-HTTP", + "repository" : { + "type" : "git", + "url" : "https://github.com/libwww-perl/Net-HTTP.git", + "web" : "https://github.com/libwww-perl/Net-HTTP" + }, + "x_IRC" : "irc://irc.perl.org/#lwp", + "x_MailingList" : "mailto:libwww@perl.org" + }, + "version" : "6.09", + "x_contributors" : [ + "Adam Kennedy ", + "Adam Sjogren ", + "Alexey Tourbin ", + "Alex Kapranoff ", + "amire80 ", + "Andreas J. Koenig ", + "Bill Mann ", + "Bron Gondwana ", + "Dagfinn Ilmari Manns\u00e5ker ", + "Daniel Hedlund ", + "David E. Wheeler ", + "DAVIDRW ", + "David Steinbrunner ", + "Eric Wong ", + "Father Chrysostomos ", + "FWILES ", + "Gavin Peters ", + "Gisle Aas ", + "Gisle Aas ", + "Gisle Aas ", + "Gisle Aas ", + "Graeme Thompson ", + "Hans-H. Froehlich ", + "Ian Kilgore ", + "Jacob J ", + "Jason A Fesler ", + "Jay Hannah ", + "jefflee ", + "Jesse Luehrs ", + "john9art ", + "Karen Etheridge ", + "Lasse Makholm ", + "Marinos Yannikos ", + "Mark Overmeer ", + "Mark Stosberg ", + "Mark Stosberg ", + "Mark Stosberg ", + "Mike Schilli ", + "Mike Schilli ", + "murphy ", + "Olaf Alders ", + "Ondrej Hanak ", + "Peter Rabbitson ", + "phrstbrn ", + "Robert Stone ", + "Rolf Grossmann ", + "ruff ", + "sasao ", + "Sean M. Burke ", + "Slaven Rezic ", + "Slaven Rezic ", + "Spiros Denaxas ", + "Steve Hay ", + "Todd Lipcon ", + "Tom Hukins ", + "Tony Finch ", + "Toru Yamaguchi ", + "uid39246 ", + "Ville Skytta ", + "Yuri Karaban ", + "Zefram " + ], + "x_serialization_backend" : "Cpanel::JSON::XS version 3.0218" +} + diff --git a/Makefile.PL b/Makefile.PL index 3a8553ed..deb1135c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,112 +1,81 @@ -#!perl -w - -require 5.006002; +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007. use strict; -use ExtUtils::MakeMaker; -use Getopt::Long qw(GetOptions); -GetOptions(\my %opt, 'live-tests',) or warn "Usage: $0 [--live-tests]\n"; +use warnings; -my $flag_file = "t/LIVE_TESTS"; -if ($opt{"live-tests"}) { - open(my $fh, ">", $flag_file) || die; -} -else { - unlink($flag_file); -} +use 5.006002; -my $developer = -f '.gitignore'; -ExtUtils::MakeMaker->VERSION(6.98) if $developer; +use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( - NAME => 'Net::HTTP', - VERSION_FROM => 'lib/Net/HTTP.pm', - ABSTRACT_FROM => 'lib/Net/HTTP.pm', - AUTHOR => 'Gisle Aas ', - LICENSE => 'perl_5', - MIN_PERL_VERSION => 5.006002, - PREREQ_PM => { - 'IO::Socket::INET' => 0, - 'IO::Select' => 0, - 'Compress::Raw::Zlib' => 0, - 'IO::Uncompress::Gunzip' => 0, - 'URI' => 0, - }, - META_MERGE => { - 'meta-spec' => { version => 2 }, - dynamic_config => 0, - prereqs => { - runtime => { - recommends => { - 'IO::Socket::SSL' => "1.38", - }, - }, - }, - resources => { - repository => { - url => 'https://github.com/libwww-perl/net-http.git', - web => 'https://github.com/libwww-perl/net-http', - type => 'git', - }, - bugtracker => { - mailto => 'bug-Net-HTTP@rt.cpan.org', - web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Net-HTTP', - }, - x_MailingList => 'mailto:libwww@perl.org', - x_IRC => 'irc://irc.perl.org/#lwp', - }, - }, + "ABSTRACT" => "Low-level HTTP connection (client)", + "AUTHOR" => "Gisle Aas ", + "CONFIGURE_REQUIRES" => { + "ExtUtils::MakeMaker" => 0 + }, + "DISTNAME" => "Net-HTTP", + "LICENSE" => "perl", + "MIN_PERL_VERSION" => "5.006002", + "NAME" => "Net::HTTP", + "PREREQ_PM" => { + "Carp" => 0, + "Compress::Raw::Zlib" => 0, + "IO::Socket" => 0, + "IO::Socket::INET" => 0, + "IO::Socket::INET6" => 0, + "IO::Socket::IP" => 0, + "IO::Socket::SSL" => 0, + "IO::Uncompress::Gunzip" => 0, + "Net::SSL" => 0, + "Symbol" => 0, + "URI" => 0, + "base" => 0, + "strict" => 0, + "vars" => 0, + "warnings" => 0 + }, + "TEST_REQUIRES" => { + "Data::Dumper" => 0, + "IO::Select" => 0, + "Socket" => 0, + "Test::More" => 0 + }, + "VERSION" => "6.09", + "test" => { + "TESTS" => "t/*.t" + } ); -my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; - -for (qw(configure build test runtime)) { - my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; - next unless exists $WriteMakefileArgs{META_ADD}{prereqs}{$_} - or exists $WriteMakefileArgs{$key}; - my $r = $WriteMakefileArgs{$key} = { - %{$WriteMakefileArgs{META_ADD}{prereqs}{$_}{requires} || {}}, - %{delete $WriteMakefileArgs{$key} || {}}, - }; - defined $r->{$_} or delete $r->{$_} for keys %$r; -} - -# dynamic prereqs get added here. -$WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0; - -die 'attention developer: you need to do a sane meta merge here!' - if keys %{$WriteMakefileArgs{BUILD_REQUIRES}}; +my %FallbackPrereqs = ( + "Carp" => 0, + "Compress::Raw::Zlib" => 0, + "Data::Dumper" => 0, + "IO::Select" => 0, + "IO::Socket" => 0, + "IO::Socket::INET" => 0, + "IO::Socket::INET6" => 0, + "IO::Socket::IP" => 0, + "IO::Socket::SSL" => 0, + "IO::Uncompress::Gunzip" => 0, + "Net::SSL" => 0, + "Socket" => 0, + "Symbol" => 0, + "Test::More" => 0, + "URI" => 0, + "base" => 0, + "strict" => 0, + "vars" => 0, + "warnings" => 0 +); -$WriteMakefileArgs{BUILD_REQUIRES} = { - %{$WriteMakefileArgs{BUILD_REQUIRES} || {}}, - %{delete $WriteMakefileArgs{TEST_REQUIRES}} -} if $eumm_version < 6.63_03; -$WriteMakefileArgs{PREREQ_PM} = { - %{$WriteMakefileArgs{PREREQ_PM}}, - %{delete $WriteMakefileArgs{BUILD_REQUIRES}} -} if $eumm_version < 6.55_01; +unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { + delete $WriteMakefileArgs{TEST_REQUIRES}; + delete $WriteMakefileArgs{BUILD_REQUIRES}; + $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; +} delete $WriteMakefileArgs{CONFIGURE_REQUIRES} - if $eumm_version < 6.51_03; - -delete $WriteMakefileArgs{MIN_PERL_VERSION} - if $eumm_version < 6.48; - -delete @WriteMakefileArgs{qw(META_ADD META_MERGE)} - if $eumm_version < 6.46; - -delete $WriteMakefileArgs{LICENSE} - if $eumm_version < 6.31; + unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); - -# pod2text is in https://metacpan.org/release/podlators -system("pod2text $WriteMakefileArgs{VERSION_FROM} > README") - if $developer - and (not -e 'README' or (stat('README'))[9] < (stat($WriteMakefileArgs{VERSION_FROM}))[9]); - -# pod2markdown is in https://metacpan.org/release/Pod-Markdown -system("pod2markdown $WriteMakefileArgs{VERSION_FROM} > README.md") - if $developer - and (not -e 'README.md' or (stat('README.md'))[9] < (stat($WriteMakefileArgs{VERSION_FROM}))[9]); diff --git a/README b/README deleted file mode 100644 index 3029acd7..00000000 --- a/README +++ /dev/null @@ -1,222 +0,0 @@ -NAME - Net::HTTP - Low-level HTTP connection (client) - -SYNOPSIS - use Net::HTTP; - my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; - $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); - my($code, $mess, %h) = $s->read_response_headers; - - while (1) { - my $buf; - my $n = $s->read_entity_body($buf, 1024); - die "read failed: $!" unless defined $n; - last unless $n; - print $buf; - } - -DESCRIPTION - The "Net::HTTP" class is a low-level HTTP client. An instance of the - "Net::HTTP" class represents a connection to an HTTP server. The HTTP - protocol is described in RFC 2616. The "Net::HTTP" class supports - "HTTP/1.0" and "HTTP/1.1". - - "Net::HTTP" is a sub-class of one of "IO::Socket::IP" (IPv6+IPv4), - "IO::Socket::INET6" (IPv6+IPv4), or "IO::Socket::INET" (IPv4 only). You - can mix the methods described below with reading and writing from the - socket directly. This is not necessary a good idea, unless you know what - you are doing. - - The following methods are provided (in addition to those of - "IO::Socket::INET"): - - $s = Net::HTTP->new( %options ) - The "Net::HTTP" constructor method takes the same options as - "IO::Socket::INET"'s as well as these: - - Host: Initial host attribute value - KeepAlive: Initial keep_alive attribute value - SendTE: Initial send_te attribute_value - HTTPVersion: Initial http_version attribute value - PeerHTTPVersion: Initial peer_http_version attribute value - MaxLineLength: Initial max_line_length attribute value - MaxHeaderLines: Initial max_header_lines attribute value - - The "Host" option is also the default for "IO::Socket::INET"'s - "PeerAddr". The "PeerPort" defaults to 80 if not provided. The - "PeerPort" specification can also be embedded in the "PeerAddr" by - preceding it with a ":", and closing the IPv6 address on brackets - "[]" if necessary: - "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". - - The "Listen" option provided by "IO::Socket::INET"'s constructor - method is not allowed. - - If unable to connect to the given HTTP server then the constructor - returns "undef" and $@ contains the reason. After a successful - connect, a "Net:HTTP" object is returned. - - $s->host - Get/set the default value of the "Host" header to send. The $host - must not be set to an empty string (or "undef") for HTTP/1.1. - - $s->keep_alive - Get/set the *keep-alive* value. If this value is TRUE then the - request will be sent with headers indicating that the server should - try to keep the connection open so that multiple requests can be - sent. - - The actual headers set will depend on the value of the - "http_version" and "peer_http_version" attributes. - - $s->send_te - Get/set the a value indicating if the request will be sent with a - "TE" header to indicate the transfer encodings that the server can - choose to use. The list of encodings announced as accepted by this - client depends on availability of the following modules: - "Compress::Raw::Zlib" for *deflate*, and "IO::Compress::Gunzip" for - *gzip*. - - $s->http_version - Get/set the HTTP version number that this client should announce. - This value can only be set to "1.0" or "1.1". The default is "1.1". - - $s->peer_http_version - Get/set the protocol version number of our peer. This value will - initially be "1.0", but will be updated by a successful - read_response_headers() method call. - - $s->max_line_length - Get/set a limit on the length of response line and response header - lines. The default is 8192. A value of 0 means no limit. - - $s->max_header_length - Get/set a limit on the number of header lines that a response can - have. The default is 128. A value of 0 means no limit. - - $s->format_request($method, $uri, %headers, [$content]) - Format a request message and return it as a string. If the headers - do not include a "Host" header, then a header is inserted with the - value of the "host" attribute. Headers like "Connection" and - "Keep-Alive" might also be added depending on the status of the - "keep_alive" attribute. - - If $content is given (and it is non-empty), then a "Content-Length" - header is automatically added unless it was already present. - - $s->write_request($method, $uri, %headers, [$content]) - Format and send a request message. Arguments are the same as for - format_request(). Returns true if successful. - - $s->format_chunk( $data ) - Returns the string to be written for the given chunk of data. - - $s->write_chunk($data) - Will write a new chunk of request entity body data. This method - should only be used if the "Transfer-Encoding" header with a value - of "chunked" was sent in the request. Note, writing zero-length data - is a no-op. Use the write_chunk_eof() method to signal end of entity - body data. - - Returns true if successful. - - $s->format_chunk_eof( %trailers ) - Returns the string to be written for signaling EOF when a - "Transfer-Encoding" of "chunked" is used. - - $s->write_chunk_eof( %trailers ) - Will write eof marker for chunked data and optional trailers. Note - that trailers should not really be used unless is was signaled with - a "Trailer" header. - - Returns true if successful. - - ($code, $mess, %headers) = $s->read_response_headers( %opts ) - Read response headers from server and return it. The $code is the 3 - digit HTTP status code (see HTTP::Status) and $mess is the textual - message that came with it. Headers are then returned as key/value - pairs. Since key letter casing is not normalized and the same key - can even occur multiple times, assigning these values directly to a - hash is not wise. Only the $code is returned if this method is - called in scalar context. - - As a side effect this method updates the 'peer_http_version' - attribute. - - Options might be passed in as key/value pairs. There are currently - only two options supported; "laxed" and "junk_out". - - The "laxed" option will make read_response_headers() more forgiving - towards servers that have not learned how to speak HTTP properly. - The "laxed" option is a boolean flag, and is enabled by passing in a - TRUE value. The "junk_out" option can be used to capture bad header - lines when "laxed" is enabled. The value should be an array - reference. Bad header lines will be pushed onto the array. - - The "laxed" option must be specified in order to communicate with - pre-HTTP/1.0 servers that don't describe the response outcome or the - data they send back with a header block. For these servers - peer_http_version is set to "0.9" and this method returns (200, - "Assumed OK"). - - The method will raise an exception (die) if the server does not - speak proper HTTP or if the "max_line_length" or "max_header_length" - limits are reached. If the "laxed" option is turned on and - "max_line_length" and "max_header_length" checks are turned off, - then no exception will be raised and this method will always return - a response code. - - $n = $s->read_entity_body($buf, $size); - Reads chunks of the entity body content. Basically the same - interface as for read() and sysread(), but the buffer offset - argument is not supported yet. This method should only be called - after a successful read_response_headers() call. - - The return value will be "undef" on read errors, 0 on EOF, -1 if no - data could be returned this time, otherwise the number of bytes - assigned to $buf. The $buf is set to "" when the return value is -1. - - You normally want to retry this call if this function returns either - -1 or "undef" with $! as EINTR or EAGAIN (see Errno). EINTR can - happen if the application catches signals and EAGAIN can happen if - you made the socket non-blocking. - - This method will raise exceptions (die) if the server does not speak - proper HTTP. This can only happen when reading chunked data. - - %headers = $s->get_trailers - After read_entity_body() has returned 0 to indicate end of the - entity body, you might call this method to pick up any trailers. - - $s->_rbuf - Get/set the read buffer content. The read_response_headers() and - read_entity_body() methods use an internal buffer which they will - look for data before they actually sysread more from the socket - itself. If they read too much, the remaining data will be left in - this buffer. - - $s->_rbuf_length - Returns the number of bytes in the read buffer. This should always - be the same as: - - length($s->_rbuf) - - but might be more efficient. - -SUBCLASSING - The read_response_headers() and read_entity_body() will invoke the - sysread() method when they need more data. Subclasses might want to - override this method to control how reading takes place. - - The object itself is a glob. Subclasses should avoid using hash key - names prefixed with "http_" and "io_". - -SEE ALSO - LWP, IO::Socket::INET, Net::HTTP::NB - -COPYRIGHT - Copyright 2001-2003 Gisle Aas. - - This library is free software; you can redistribute it and/or modify it - under the same terms as Perl itself. - diff --git a/README.md b/README.md index 61a2884e..52584667 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # NAME -Net::HTTP - Low-level HTTP connection (client) +Net::HTTP + +[![Build Status](https://travis-ci.org/libwww-perl/Net-HTTP.png?branch=master)](https://travis-ci.org/libwww-perl/Net-HTTP) + +# VERSION + +version 6.09 # SYNOPSIS @@ -221,6 +227,10 @@ The following methods are provided (in addition to those of but might be more efficient. +# NAME + +Net::HTTP - Low-level HTTP connection (client) + # SUBCLASSING The read\_response\_headers() and read\_entity\_body() will invoke the @@ -240,3 +250,14 @@ Copyright 2001-2003 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +# AUTHOR + +Gisle Aas + +# COPYRIGHT AND LICENSE + +This software is copyright (c) 2001-2016 by Gisle Aas. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. diff --git a/cpanfile b/cpanfile new file mode 100644 index 00000000..cbae1be5 --- /dev/null +++ b/cpanfile @@ -0,0 +1,35 @@ +requires "Carp" => "0"; +requires "Compress::Raw::Zlib" => "0"; +requires "IO::Socket" => "0"; +requires "IO::Socket::INET" => "0"; +requires "IO::Socket::INET6" => "0"; +requires "IO::Socket::IP" => "0"; +requires "IO::Socket::SSL" => "0"; +requires "IO::Uncompress::Gunzip" => "0"; +requires "Net::SSL" => "0"; +requires "Symbol" => "0"; +requires "URI" => "0"; +requires "base" => "0"; +requires "perl" => "5.006002"; +requires "strict" => "0"; +requires "vars" => "0"; +requires "warnings" => "0"; + +on 'test' => sub { + requires "Data::Dumper" => "0"; + requires "IO::Select" => "0"; + requires "Socket" => "0"; + requires "Test::More" => "0"; +}; + +on 'configure' => sub { + requires "ExtUtils::MakeMaker" => "0"; +}; + +on 'configure' => sub { + suggests "JSON::PP" => "2.27300"; +}; + +on 'develop' => sub { + requires "Test::CPAN::Changes" => "0.19"; +}; diff --git a/dist.ini b/dist.ini new file mode 100644 index 00000000..0ff3b088 --- /dev/null +++ b/dist.ini @@ -0,0 +1,23 @@ +name = Net-HTTP +author = Gisle Aas +license = Perl_5 +main_module = lib/Net/HTTP.pm +copyright_holder = Gisle Aas +copyright_year = 2001-2016 +version = 6.09 + +[MetaResources] +x_IRC = irc://irc.perl.org/#lwp +x_MailingList = mailto:libwww@perl.org + +[Prereqs] +perl = 5.006002 + +[@Author::OALDERS] +-remove = MinimumPerl +-remove = PodCoverageTests +-remove = Prereqs +-remove = Test::Perl::Critic +-remove = Test::PodSpelling +-remove = Test::Synopsis +-remove = Test::TidyAll diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index cba27452..c8be63ff 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -3,9 +3,6 @@ package Net::HTTP; use strict; use warnings; -our $VERSION = "6.09"; -$VERSION = eval $VERSION; - use vars qw($SOCKET_CLASS); unless ($SOCKET_CLASS) { # Try several, in order of capability and preference diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 4f4249c7..152f3dec 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -4,9 +4,6 @@ use strict; use warnings; use URI; -our $VERSION = "6.09"; -$VERSION = eval $VERSION; - my $CRLF = "\015\012"; # "\r\n" is not portable *_bytes = defined(&utf8::downgrade) ? diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index fb72740f..f7179ab9 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -3,9 +3,6 @@ package Net::HTTP::NB; use strict; use warnings; -our $VERSION = "6.09"; -$VERSION = eval $VERSION; - use base 'Net::HTTP'; sub can_read { diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 06e38179..37f5d2e3 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -3,9 +3,6 @@ package Net::HTTPS; use strict; use warnings; -our $VERSION = "6.09"; -$VERSION = eval $VERSION; - # Figure out which SSL implementation to use use vars qw($SSL_SOCKET_CLASS); if ($SSL_SOCKET_CLASS) { diff --git a/perlcriticrc b/perlcriticrc new file mode 100644 index 00000000..7819a28c --- /dev/null +++ b/perlcriticrc @@ -0,0 +1,86 @@ +severity = 3 +verbose = 11 + +theme = core + pbp + bugs + maintenance + cosmetic + complexity + security + tests + moose + +exclude = Subroutines::ProhibitCallsToUndeclaredSubs + +[BuiltinFunctions::ProhibitStringySplit] +severity = 3 + +[CodeLayout::RequireTrailingCommas] +severity = 3 + +[ControlStructures::ProhibitCStyleForLoops] +severity = 3 + +[InputOutput::RequireCheckedSyscalls] +functions = :builtins +exclude_functions = sleep +severity = 3 + +[Moose::RequireCleanNamespace] +modules = Moose Moose::Role MooseX::Role::Parameterized Moose::Util::TypeConstraints +cleaners = namespace::autoclean + +[NamingConventions::Capitalization] +package_exemptions = [A-Z]\w+|minFraud +file_lexical_variables = [A-Z]\w+|[^A-Z]+ +global_variables = :starts_with_upper +scoped_lexical_variables = [A-Z]\w+|[^A-Z]+ +severity = 3 + +# Given our code base, leaving this at 5 would be a huge pain +[Subroutines::ProhibitManyArgs] +max_arguments = 10 + +[RegularExpressions::ProhibitComplexRegexes] +max_characters = 200 + +[RegularExpressions::ProhibitUnusualDelimiters] +severity = 3 + +[Subroutines::ProhibitUnusedPrivateSubroutines] +private_name_regex = _(?!build)\w+ +skip_when_using = Moo::Role Moose::Role MooseX::Role::Parameterized Role::Tiny Test::Class::Moose::Role + +[TestingAndDebugging::ProhibitNoWarnings] +allow = redefine + +[ValuesAndExpressions::ProhibitEmptyQuotes] +severity = 3 + +[ValuesAndExpressions::ProhibitInterpolationOfLiterals] +severity = 3 + +[ValuesAndExpressions::RequireUpperCaseHeredocTerminator] +severity = 3 + +[Variables::ProhibitPackageVars] +add_packages = Test::Builder + +[TestingAndDebugging::RequireUseStrict] + +[TestingAndDebugging::RequireUseWarnings] + +[-ControlStructures::ProhibitCascadingIfElse] + +[-ErrorHandling::RequireCarping] +[-InputOutput::RequireBriefOpen] + +[-ValuesAndExpressions::ProhibitConstantPragma] + +# No need for /xsm everywhere +[-RegularExpressions::RequireDotMatchAnything] +[-RegularExpressions::RequireExtendedFormatting] +[-RegularExpressions::RequireLineBoundaryMatching] + +[-Subroutines::ProhibitExplicitReturnUndef] + +# http://stackoverflow.com/questions/2275317/why-does-perlcritic-dislike-using-shift-to-populate-subroutine-variables +[-Subroutines::RequireArgUnpacking] + +[-Subroutines::RequireFinalReturn] + +# "use v5.14" is more readable than "use 5.014" +[-ValuesAndExpressions::ProhibitVersionStrings] diff --git a/perltidyrc b/perltidyrc new file mode 100644 index 00000000..b7ed6247 --- /dev/null +++ b/perltidyrc @@ -0,0 +1,12 @@ +--blank-lines-before-packages=0 +--iterations=2 +--no-outdent-long-comments +-b +-bar +-boc +-ci=4 +-i=4 +-l=78 +-nolq +-se +-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" diff --git a/tidyall.ini b/tidyall.ini new file mode 100644 index 00000000..67ea245d --- /dev/null +++ b/tidyall.ini @@ -0,0 +1,19 @@ +[PerlTidy] +select = **/*.{pl,pm,t,psgi} +ignore = t/00-* +ignore = t/author-* +ignore = t/release-* +ignore = blib/**/* +ignore = .build/**/* +ignore = Net-HTTP-*/**/* +argv = --profile=$ROOT/perltidyrc + +[PerlCritic] +select = **/*.{pl,pm,t,psgi} +ignore = t/00-* +ignore = t/author-* +ignore = t/release-* +ignore = blib/**/* +ignore = .build/**/* +ignore = Net-HTTP-*/**/* +argv = --profile $ROOT/perlcriticrc --program-extensions .pl --program-extensions .t --program-extensions .psgi From efe2af55aac7a850f8c734e994e443e3c25ca660 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 22:47:42 -0500 Subject: [PATCH 35/52] Adds IO::Socket::SSL to runtime recommends. --- META.json | 3 +++ cpanfile | 1 + dist.ini | 3 +++ 3 files changed, 7 insertions(+) diff --git a/META.json b/META.json index 0ee2e580..e82d128c 100644 --- a/META.json +++ b/META.json @@ -35,6 +35,9 @@ } }, "runtime" : { + "recommends" : { + "IO::Socket::SSL" : "1.38" + }, "requires" : { "Carp" : "0", "Compress::Raw::Zlib" : "0", diff --git a/cpanfile b/cpanfile index cbae1be5..aa5b6381 100644 --- a/cpanfile +++ b/cpanfile @@ -14,6 +14,7 @@ requires "perl" => "5.006002"; requires "strict" => "0"; requires "vars" => "0"; requires "warnings" => "0"; +recommends "IO::Socket::SSL" => "1.38"; on 'test' => sub { requires "Data::Dumper" => "0"; diff --git a/dist.ini b/dist.ini index 0ff3b088..3ff85a80 100644 --- a/dist.ini +++ b/dist.ini @@ -13,6 +13,9 @@ x_MailingList = mailto:libwww@perl.org [Prereqs] perl = 5.006002 +[Prereqs / RuntimeRecommends] +IO::Socket::SSL = 1.38 + [@Author::OALDERS] -remove = MinimumPerl -remove = PodCoverageTests From 23cc51195a5c7ee200aba81720c6fbd50af0211c Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 22:48:33 -0500 Subject: [PATCH 36/52] Changes made by dzil. --- Install | 14 +++++++------- META.json | 5 +++-- Makefile.PL | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Install b/Install index 457aa220..c1fb5f40 100644 --- a/Install +++ b/Install @@ -8,10 +8,10 @@ If you have cpanm, you only need one line: % cpanm Net::HTTP -If you are installing into a system-wide directory, you may need to pass the -"-S" flag to cpanm, which uses sudo to install the module: - - % cpanm -S Net::HTTP +If it does not have permission to install modules to the current perl, cpanm +will automatically set up and install to a local::lib in your home directory. +See the local::lib documentation (https://metacpan.org/pod/local::lib) for +details on enabling it in your environment. ## Installing with the CPAN shell @@ -31,9 +31,9 @@ Then install it: % make install -If you are installing into a system-wide directory, you may need to run: - - % sudo make install +If your perl is system-managed, you can create a local::lib in your home +directory to install modules to. For details, see the local::lib documentation: +https://metacpan.org/pod/local::lib ## Documentation diff --git a/META.json b/META.json index e82d128c..9aa398af 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ "Gisle Aas " ], "dynamic_config" : 0, - "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150005", + "generated_by" : "Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], @@ -88,6 +88,7 @@ "Alex Kapranoff ", "amire80 ", "Andreas J. Koenig ", + "Andy Grundman ", "Bill Mann ", "Bron Gondwana ", "Dagfinn Ilmari Manns\u00e5ker ", @@ -144,6 +145,6 @@ "Yuri Karaban ", "Zefram " ], - "x_serialization_backend" : "Cpanel::JSON::XS version 3.0218" + "x_serialization_backend" : "Cpanel::JSON::XS version 3.0225" } diff --git a/Makefile.PL b/Makefile.PL index deb1135c..f44d0baa 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,4 +1,4 @@ -# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007. +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008. use strict; use warnings; From 2e09a219914234f5912e0d1b22db89e12a6c92bc Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 22:50:22 -0500 Subject: [PATCH 37/52] gitignore t/LIVE_TESTS. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 188b4582..2bce033e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ xx* /MANIFEST.SKIP.bak /Net-HTTP-*/ /Net-HTTP-*.tar.gz +t/LIVE_TESTS +.tidyall.d From 11f228f359d948ececc93b8eaa5e432362482093 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 23:10:17 -0500 Subject: [PATCH 38/52] Remove more boilerplate that dzil manages. --- lib/Net/HTTP.pm | 11 +---------- lib/Net/HTTP/NB.pm | 11 +---------- lib/Net/HTTPS.pm | 5 ++--- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/Net/HTTP.pm b/lib/Net/HTTP.pm index c8be63ff..68b1f6e1 100644 --- a/lib/Net/HTTP.pm +++ b/lib/Net/HTTP.pm @@ -42,9 +42,7 @@ sub http_connect { __END__ -=head1 NAME - -Net::HTTP - Low-level HTTP connection (client) +# ABSTRACT: Low-level HTTP connection (client) =head1 SYNOPSIS @@ -282,11 +280,4 @@ names prefixed with C and C. L, L, L -=head1 COPYRIGHT - -Copyright 2001-2003 Gisle Aas. - -This library is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - =cut diff --git a/lib/Net/HTTP/NB.pm b/lib/Net/HTTP/NB.pm index f7179ab9..202d8364 100644 --- a/lib/Net/HTTP/NB.pm +++ b/lib/Net/HTTP/NB.pm @@ -52,9 +52,7 @@ sub read_entity_body { __END__ -=head1 NAME - -Net::HTTP::NB - Non-blocking HTTP client +#ABSTRACT: Non-blocking HTTP client =head1 SYNOPSIS @@ -96,11 +94,4 @@ the value -1 is returned. L -=head1 COPYRIGHT - -Copyright 2001 Gisle Aas. - -This library is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. - =cut diff --git a/lib/Net/HTTPS.pm b/lib/Net/HTTPS.pm index 37f5d2e3..d5fd2b5a 100644 --- a/lib/Net/HTTPS.pm +++ b/lib/Net/HTTPS.pm @@ -79,10 +79,9 @@ if ($SSL_SOCKET_CLASS eq "Net::SSL") { } 1; +__END__ -=head1 NAME - -Net::HTTPS - Low-level HTTP over SSL/TLS connection (client) +#ABSTRACT: Low-level HTTP over SSL/TLS connection (client) =head1 DESCRIPTION From 946201dcff7e36c174f97e91600a647f46a84e32 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 23:10:39 -0500 Subject: [PATCH 39/52] Convert Changes to dzil. --- Changes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changes b/Changes index 2e4f7af0..71bad5c0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Release history for Net-HTTP +_______________________________________________________________________________ +{{$NEXT}} Karen Etheridge (4): Added LICENSE From d15878fd56c0d0e088d84a11bc87f218fb3f2fb7 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 23:10:50 -0500 Subject: [PATCH 40/52] Update Changes. --- Changes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changes b/Changes index 71bad5c0..622534fb 100644 --- a/Changes +++ b/Changes @@ -9,7 +9,11 @@ Karen Etheridge (4): Drop all use of Test.pm Removed unneeded uses of 'use vars' +Andy Grundman (1): + Switch live tests to use Google. +Lasse Makholm (1): + Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0 _______________________________________________________________________________ 2015-05-20 Net-HTTP 6.09 From d87c27a8df3b77fa542bbdf45596bb376641267c Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Thu, 29 Dec 2016 23:11:16 -0500 Subject: [PATCH 41/52] Bumps version to 6.10 --- META.json | 2 +- Makefile.PL | 2 +- dist.ini | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/META.json b/META.json index 9aa398af..716cdf6d 100644 --- a/META.json +++ b/META.json @@ -80,7 +80,7 @@ "x_IRC" : "irc://irc.perl.org/#lwp", "x_MailingList" : "mailto:libwww@perl.org" }, - "version" : "6.09", + "version" : "6.10", "x_contributors" : [ "Adam Kennedy ", "Adam Sjogren ", diff --git a/Makefile.PL b/Makefile.PL index f44d0baa..b7e4f794 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -39,7 +39,7 @@ my %WriteMakefileArgs = ( "Socket" => 0, "Test::More" => 0 }, - "VERSION" => "6.09", + "VERSION" => "6.10", "test" => { "TESTS" => "t/*.t" } diff --git a/dist.ini b/dist.ini index 3ff85a80..8c60c9ff 100644 --- a/dist.ini +++ b/dist.ini @@ -4,7 +4,7 @@ license = Perl_5 main_module = lib/Net/HTTP.pm copyright_holder = Gisle Aas copyright_year = 2001-2016 -version = 6.09 +version = 6.10 [MetaResources] x_IRC = irc://irc.perl.org/#lwp From 88122e9e151998a3291866e113535f97ba878c91 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Fri, 30 Dec 2016 01:20:58 -0500 Subject: [PATCH 42/52] Ignore .build files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2bce033e..9bdf35df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /Makefile +.build /Makefile.old /blib/ /pm_to_blib From 1b6887486499b6ba76760637b0d7442932cfcf69 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Fri, 30 Dec 2016 01:21:11 -0500 Subject: [PATCH 43/52] Changes file won't pass dzil tests. --- cpanfile | 4 ---- dist.ini | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cpanfile b/cpanfile index aa5b6381..d6e73fb1 100644 --- a/cpanfile +++ b/cpanfile @@ -30,7 +30,3 @@ on 'configure' => sub { on 'configure' => sub { suggests "JSON::PP" => "2.27300"; }; - -on 'develop' => sub { - requires "Test::CPAN::Changes" => "0.19"; -}; diff --git a/dist.ini b/dist.ini index 8c60c9ff..8fac3a6d 100644 --- a/dist.ini +++ b/dist.ini @@ -17,9 +17,11 @@ perl = 5.006002 IO::Socket::SSL = 1.38 [@Author::OALDERS] +-remove = CheckChangesHasContent -remove = MinimumPerl -remove = PodCoverageTests -remove = Prereqs +-remove = Test::CPAN::Changes -remove = Test::Perl::Critic -remove = Test::PodSpelling -remove = Test::Synopsis From 828345de3de902aaa2525b7bb0749f9c5e1a8508 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Fri, 30 Dec 2016 01:21:55 -0500 Subject: [PATCH 44/52] v6.10 --- Changes | 2 + META.json | 7 +- README.md | 347 ++++++++++++++++++++++++++---------------------------- 3 files changed, 170 insertions(+), 186 deletions(-) diff --git a/Changes b/Changes index 622534fb..6f65898a 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Release history for Net-HTTP _______________________________________________________________________________ {{$NEXT}} +6.10 2016-12-30 01:21:48-05:00 America/Toronto (TRIAL RELEASE) + Karen Etheridge (4): Added LICENSE Added 'use warnings' to everywhere that lacked it diff --git a/META.json b/META.json index 716cdf6d..3191c392 100644 --- a/META.json +++ b/META.json @@ -29,11 +29,6 @@ "JSON::PP" : "2.27300" } }, - "develop" : { - "requires" : { - "Test::CPAN::Changes" : "0.19" - } - }, "runtime" : { "recommends" : { "IO::Socket::SSL" : "1.38" @@ -66,7 +61,7 @@ } } }, - "release_status" : "stable", + "release_status" : "testing", "resources" : { "bugtracker" : { "web" : "https://github.com/libwww-perl/Net-HTTP/issues" diff --git a/README.md b/README.md index 52584667..9521fe6f 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,46 @@ -# NAME +NAME -Net::HTTP + Net::HTTP - Low-level HTTP connection (client) -[![Build Status](https://travis-ci.org/libwww-perl/Net-HTTP.png?branch=master)](https://travis-ci.org/libwww-perl/Net-HTTP) +VERSION -# VERSION + version 6.10 -version 6.09 +SYNOPSIS -# SYNOPSIS + use Net::HTTP; + my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; + $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); + my($code, $mess, %h) = $s->read_response_headers; + + while (1) { + my $buf; + my $n = $s->read_entity_body($buf, 1024); + die "read failed: $!" unless defined $n; + last unless $n; + print $buf; + } - use Net::HTTP; - my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; - $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); - my($code, $mess, %h) = $s->read_response_headers; +DESCRIPTION - while (1) { - my $buf; - my $n = $s->read_entity_body($buf, 1024); - die "read failed: $!" unless defined $n; - last unless $n; - print $buf; - } + The Net::HTTP class is a low-level HTTP client. An instance of the + Net::HTTP class represents a connection to an HTTP server. The HTTP + protocol is described in RFC 2616. The Net::HTTP class supports + HTTP/1.0 and HTTP/1.1. -# DESCRIPTION + Net::HTTP is a sub-class of one of IO::Socket::IP (IPv6+IPv4), + IO::Socket::INET6 (IPv6+IPv4), or IO::Socket::INET (IPv4 only). You can + mix the methods described below with reading and writing from the + socket directly. This is not necessary a good idea, unless you know + what you are doing. -The `Net::HTTP` class is a low-level HTTP client. An instance of the -`Net::HTTP` class represents a connection to an HTTP server. The -HTTP protocol is described in RFC 2616. The `Net::HTTP` class -supports `HTTP/1.0` and `HTTP/1.1`. + The following methods are provided (in addition to those of + IO::Socket::INET): -`Net::HTTP` is a sub-class of one of `IO::Socket::IP` (IPv6+IPv4), -`IO::Socket::INET6` (IPv6+IPv4), or `IO::Socket::INET` (IPv4 only). -You can mix the methods described below with reading and writing from the -socket directly. This is not necessary a good idea, unless you know what -you are doing. + $s = Net::HTTP->new( %options ) -The following methods are provided (in addition to those of -`IO::Socket::INET`): - -- $s = Net::HTTP->new( %options ) - - The `Net::HTTP` constructor method takes the same options as - `IO::Socket::INET`'s as well as these: + The Net::HTTP constructor method takes the same options as + IO::Socket::INET's as well as these: Host: Initial host attribute value KeepAlive: Initial keep_alive attribute value @@ -52,212 +50,201 @@ The following methods are provided (in addition to those of MaxLineLength: Initial max_line_length attribute value MaxHeaderLines: Initial max_header_lines attribute value - The `Host` option is also the default for `IO::Socket::INET`'s - `PeerAddr`. The `PeerPort` defaults to 80 if not provided. - The `PeerPort` specification can also be embedded in the `PeerAddr` - by preceding it with a ":", and closing the IPv6 address on brackets "\[\]" if - necessary: "192.0.2.1:80","\[2001:db8::1\]:80","any.example.com:80". - - The `Listen` option provided by `IO::Socket::INET`'s constructor - method is not allowed. - - If unable to connect to the given HTTP server then the constructor - returns `undef` and $@ contains the reason. After a successful - connect, a `Net:HTTP` object is returned. - -- $s->host - - Get/set the default value of the `Host` header to send. The $host - must not be set to an empty string (or `undef`) for HTTP/1.1. + The Host option is also the default for IO::Socket::INET's PeerAddr. + The PeerPort defaults to 80 if not provided. The PeerPort + specification can also be embedded in the PeerAddr by preceding it + with a ":", and closing the IPv6 address on brackets "[]" if + necessary: "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". -- $s->keep\_alive + The Listen option provided by IO::Socket::INET's constructor method + is not allowed. - Get/set the _keep-alive_ value. If this value is TRUE then the - request will be sent with headers indicating that the server should try - to keep the connection open so that multiple requests can be sent. + If unable to connect to the given HTTP server then the constructor + returns undef and $@ contains the reason. After a successful connect, + a Net:HTTP object is returned. - The actual headers set will depend on the value of the `http_version` - and `peer_http_version` attributes. + $s->host -- $s->send\_te + Get/set the default value of the Host header to send. The $host must + not be set to an empty string (or undef) for HTTP/1.1. - Get/set the a value indicating if the request will be sent with a "TE" - header to indicate the transfer encodings that the server can choose to - use. The list of encodings announced as accepted by this client depends - on availability of the following modules: `Compress::Raw::Zlib` for - _deflate_, and `IO::Compress::Gunzip` for _gzip_. + $s->keep_alive -- $s->http\_version + Get/set the keep-alive value. If this value is TRUE then the request + will be sent with headers indicating that the server should try to + keep the connection open so that multiple requests can be sent. - Get/set the HTTP version number that this client should announce. - This value can only be set to "1.0" or "1.1". The default is "1.1". + The actual headers set will depend on the value of the http_version + and peer_http_version attributes. -- $s->peer\_http\_version + $s->send_te - Get/set the protocol version number of our peer. This value will - initially be "1.0", but will be updated by a successful - read\_response\_headers() method call. + Get/set the a value indicating if the request will be sent with a + "TE" header to indicate the transfer encodings that the server can + choose to use. The list of encodings announced as accepted by this + client depends on availability of the following modules: + Compress::Raw::Zlib for deflate, and IO::Compress::Gunzip for gzip. -- $s->max\_line\_length + $s->http_version - Get/set a limit on the length of response line and response header - lines. The default is 8192. A value of 0 means no limit. + Get/set the HTTP version number that this client should announce. + This value can only be set to "1.0" or "1.1". The default is "1.1". -- $s->max\_header\_length + $s->peer_http_version - Get/set a limit on the number of header lines that a response can - have. The default is 128. A value of 0 means no limit. + Get/set the protocol version number of our peer. This value will + initially be "1.0", but will be updated by a successful + read_response_headers() method call. -- $s->format\_request($method, $uri, %headers, \[$content\]) + $s->max_line_length - Format a request message and return it as a string. If the headers do - not include a `Host` header, then a header is inserted with the value - of the `host` attribute. Headers like `Connection` and - `Keep-Alive` might also be added depending on the status of the - `keep_alive` attribute. + Get/set a limit on the length of response line and response header + lines. The default is 8192. A value of 0 means no limit. - If $content is given (and it is non-empty), then a `Content-Length` - header is automatically added unless it was already present. + $s->max_header_length -- $s->write\_request($method, $uri, %headers, \[$content\]) + Get/set a limit on the number of header lines that a response can + have. The default is 128. A value of 0 means no limit. - Format and send a request message. Arguments are the same as for - format\_request(). Returns true if successful. + $s->format_request($method, $uri, %headers, [$content]) -- $s->format\_chunk( $data ) + Format a request message and return it as a string. If the headers do + not include a Host header, then a header is inserted with the value + of the host attribute. Headers like Connection and Keep-Alive might + also be added depending on the status of the keep_alive attribute. - Returns the string to be written for the given chunk of data. + If $content is given (and it is non-empty), then a Content-Length + header is automatically added unless it was already present. -- $s->write\_chunk($data) + $s->write_request($method, $uri, %headers, [$content]) - Will write a new chunk of request entity body data. This method - should only be used if the `Transfer-Encoding` header with a value of - `chunked` was sent in the request. Note, writing zero-length data is - a no-op. Use the write\_chunk\_eof() method to signal end of entity - body data. + Format and send a request message. Arguments are the same as for + format_request(). Returns true if successful. - Returns true if successful. + $s->format_chunk( $data ) -- $s->format\_chunk\_eof( %trailers ) + Returns the string to be written for the given chunk of data. - Returns the string to be written for signaling EOF when a - `Transfer-Encoding` of `chunked` is used. + $s->write_chunk($data) -- $s->write\_chunk\_eof( %trailers ) + Will write a new chunk of request entity body data. This method + should only be used if the Transfer-Encoding header with a value of + chunked was sent in the request. Note, writing zero-length data is a + no-op. Use the write_chunk_eof() method to signal end of entity body + data. - Will write eof marker for chunked data and optional trailers. Note - that trailers should not really be used unless is was signaled - with a `Trailer` header. + Returns true if successful. - Returns true if successful. + $s->format_chunk_eof( %trailers ) -- ($code, $mess, %headers) = $s->read\_response\_headers( %opts ) + Returns the string to be written for signaling EOF when a + Transfer-Encoding of chunked is used. - Read response headers from server and return it. The $code is the 3 - digit HTTP status code (see [HTTP::Status](https://metacpan.org/pod/HTTP::Status)) and $mess is the textual - message that came with it. Headers are then returned as key/value - pairs. Since key letter casing is not normalized and the same key can - even occur multiple times, assigning these values directly to a hash - is not wise. Only the $code is returned if this method is called in - scalar context. + $s->write_chunk_eof( %trailers ) - As a side effect this method updates the 'peer\_http\_version' - attribute. + Will write eof marker for chunked data and optional trailers. Note + that trailers should not really be used unless is was signaled with a + Trailer header. - Options might be passed in as key/value pairs. There are currently - only two options supported; `laxed` and `junk_out`. + Returns true if successful. - The `laxed` option will make read\_response\_headers() more forgiving - towards servers that have not learned how to speak HTTP properly. The - `laxed` option is a boolean flag, and is enabled by passing in a TRUE - value. The `junk_out` option can be used to capture bad header lines - when `laxed` is enabled. The value should be an array reference. - Bad header lines will be pushed onto the array. + ($code, $mess, %headers) = $s->read_response_headers( %opts ) - The `laxed` option must be specified in order to communicate with - pre-HTTP/1.0 servers that don't describe the response outcome or the - data they send back with a header block. For these servers - peer\_http\_version is set to "0.9" and this method returns (200, - "Assumed OK"). + Read response headers from server and return it. The $code is the 3 + digit HTTP status code (see HTTP::Status) and $mess is the textual + message that came with it. Headers are then returned as key/value + pairs. Since key letter casing is not normalized and the same key can + even occur multiple times, assigning these values directly to a hash + is not wise. Only the $code is returned if this method is called in + scalar context. - The method will raise an exception (die) if the server does not speak - proper HTTP or if the `max_line_length` or `max_header_length` - limits are reached. If the `laxed` option is turned on and - `max_line_length` and `max_header_length` checks are turned off, - then no exception will be raised and this method will always - return a response code. + As a side effect this method updates the 'peer_http_version' + attribute. -- $n = $s->read\_entity\_body($buf, $size); + Options might be passed in as key/value pairs. There are currently + only two options supported; laxed and junk_out. - Reads chunks of the entity body content. Basically the same interface - as for read() and sysread(), but the buffer offset argument is not - supported yet. This method should only be called after a successful - read\_response\_headers() call. + The laxed option will make read_response_headers() more forgiving + towards servers that have not learned how to speak HTTP properly. The + laxed option is a boolean flag, and is enabled by passing in a TRUE + value. The junk_out option can be used to capture bad header lines + when laxed is enabled. The value should be an array reference. Bad + header lines will be pushed onto the array. - The return value will be `undef` on read errors, 0 on EOF, -1 if no data - could be returned this time, otherwise the number of bytes assigned - to $buf. The $buf is set to "" when the return value is -1. + The laxed option must be specified in order to communicate with + pre-HTTP/1.0 servers that don't describe the response outcome or the + data they send back with a header block. For these servers + peer_http_version is set to "0.9" and this method returns (200, + "Assumed OK"). - You normally want to retry this call if this function returns either - \-1 or `undef` with `$!` as EINTR or EAGAIN (see [Errno](https://metacpan.org/pod/Errno)). EINTR - can happen if the application catches signals and EAGAIN can happen if - you made the socket non-blocking. + The method will raise an exception (die) if the server does not speak + proper HTTP or if the max_line_length or max_header_length limits are + reached. If the laxed option is turned on and max_line_length and + max_header_length checks are turned off, then no exception will be + raised and this method will always return a response code. - This method will raise exceptions (die) if the server does not speak - proper HTTP. This can only happen when reading chunked data. + $n = $s->read_entity_body($buf, $size); -- %headers = $s->get\_trailers + Reads chunks of the entity body content. Basically the same interface + as for read() and sysread(), but the buffer offset argument is not + supported yet. This method should only be called after a successful + read_response_headers() call. - After read\_entity\_body() has returned 0 to indicate end of the entity - body, you might call this method to pick up any trailers. + The return value will be undef on read errors, 0 on EOF, -1 if no + data could be returned this time, otherwise the number of bytes + assigned to $buf. The $buf is set to "" when the return value is -1. -- $s->\_rbuf + You normally want to retry this call if this function returns either + -1 or undef with $! as EINTR or EAGAIN (see Errno). EINTR can happen + if the application catches signals and EAGAIN can happen if you made + the socket non-blocking. - Get/set the read buffer content. The read\_response\_headers() and - read\_entity\_body() methods use an internal buffer which they will look - for data before they actually sysread more from the socket itself. If - they read too much, the remaining data will be left in this buffer. + This method will raise exceptions (die) if the server does not speak + proper HTTP. This can only happen when reading chunked data. -- $s->\_rbuf\_length + %headers = $s->get_trailers - Returns the number of bytes in the read buffer. This should always be - the same as: + After read_entity_body() has returned 0 to indicate end of the entity + body, you might call this method to pick up any trailers. - length($s->_rbuf) + $s->_rbuf - but might be more efficient. + Get/set the read buffer content. The read_response_headers() and + read_entity_body() methods use an internal buffer which they will + look for data before they actually sysread more from the socket + itself. If they read too much, the remaining data will be left in + this buffer. -# NAME + $s->_rbuf_length -Net::HTTP - Low-level HTTP connection (client) + Returns the number of bytes in the read buffer. This should always be + the same as: -# SUBCLASSING + length($s->_rbuf) -The read\_response\_headers() and read\_entity\_body() will invoke the -sysread() method when they need more data. Subclasses might want to -override this method to control how reading takes place. + but might be more efficient. -The object itself is a glob. Subclasses should avoid using hash key -names prefixed with `http_` and `io_`. +SUBCLASSING -# SEE ALSO + The read_response_headers() and read_entity_body() will invoke the + sysread() method when they need more data. Subclasses might want to + override this method to control how reading takes place. -[LWP](https://metacpan.org/pod/LWP), [IO::Socket::INET](https://metacpan.org/pod/IO::Socket::INET), [Net::HTTP::NB](https://metacpan.org/pod/Net::HTTP::NB) + The object itself is a glob. Subclasses should avoid using hash key + names prefixed with http_ and io_. -# COPYRIGHT +SEE ALSO -Copyright 2001-2003 Gisle Aas. + LWP, IO::Socket::INET, Net::HTTP::NB -This library is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. +AUTHOR -# AUTHOR + Gisle Aas -Gisle Aas +COPYRIGHT AND LICENSE -# COPYRIGHT AND LICENSE + This software is copyright (c) 2001-2016 by Gisle Aas. -This software is copyright (c) 2001-2016 by Gisle Aas. + This is free software; you can redistribute it and/or modify it under + the same terms as the Perl 5 programming language system itself. -This is free software; you can redistribute it and/or modify it under -the same terms as the Perl 5 programming language system itself. From a69882e3027d8839fa145c9ddd12eb3e1b2824d8 Mon Sep 17 00:00:00 2001 From: Chase Whitener Date: Tue, 3 Jan 2017 10:36:30 -0500 Subject: [PATCH 45/52] Ensure Net::SSL has a pending method --- lib/Net/HTTP/Methods.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Net/HTTP/Methods.pm b/lib/Net/HTTP/Methods.pm index 152f3dec..520e5d16 100644 --- a/lib/Net/HTTP/Methods.pm +++ b/lib/Net/HTTP/Methods.pm @@ -307,7 +307,7 @@ sub can_read { my $self = shift; return 1 unless defined(fileno($self)); return 1 if $self->isa('IO::Socket::SSL') && $self->pending; - return 1 if $self->isa('Net::SSL') && $self->pending; + return 1 if $self->isa('Net::SSL') && $self->can('pending') && $self->pending; # With no timeout, wait forever. An explicit timeout of 0 can be # used to just check if the socket is readable without waiting. From 35841cd58249ff155434e98bb921f05da8a8678a Mon Sep 17 00:00:00 2001 From: Chase Whitener Date: Wed, 4 Jan 2017 14:30:56 -0500 Subject: [PATCH 46/52] reformatted the changes file --- Changes | 180 +++++++++++++++++++------------------------------------- 1 file changed, 59 insertions(+), 121 deletions(-) diff --git a/Changes b/Changes index 6f65898a..c4358766 100644 --- a/Changes +++ b/Changes @@ -1,123 +1,61 @@ -Release history for Net-HTTP +Release history for {{$dist->name}} -_______________________________________________________________________________ {{$NEXT}} - -6.10 2016-12-30 01:21:48-05:00 America/Toronto (TRIAL RELEASE) - -Karen Etheridge (4): - Added LICENSE - Added 'use warnings' to everywhere that lacked it - Drop all use of Test.pm - Removed unneeded uses of 'use vars' - -Andy Grundman (1): - Switch live tests to use Google. - -Lasse Makholm (1): - Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0 - -_______________________________________________________________________________ -2015-05-20 Net-HTTP 6.09 - -Karen Etheridge (1): - No changes since 6.08_002 - - - -_______________________________________________________________________________ -2015-05-02 Net-HTTP 6.08_002 - -Karen Etheridge (1): - fix foolish $VERSION error in 6.08_001 - - - -_______________________________________________________________________________ -2015-05-01 Net-HTTP 6.08_001 - -Mark Overmeer (1): - resolve issues with SSL by reading bytes still waiting to be read after - the initial 1024 bytes [RT#104122] - - - -_______________________________________________________________________________ -2014-07-23 Net-HTTP 6.07 - -Jason Fesler (1): - Opportunistically use IO::Socket::IP or IO::Socket::INET6. - Properly parse IPv6 literal addreses with optional port numbers. [RT#75618] - - - -_______________________________________________________________________________ -2013-03-10 Net-HTTP 6.06 - -Jesse Luehrs (1): - IO::Socket::SSL doesn't play well with select() [RT#81237] - - - -_______________________________________________________________________________ -2012-11-10 Net-HTTP 6.05 - -Gisle Aas (1): - Convert to Test::More style and disable test on Windows [RT#81090] - -Marinos Yannikos (1): - SSL broken for some servers [RT#81073] - - - -_______________________________________________________________________________ -2012-11-08 Net-HTTP 6.04 - -Gisle Aas (3): - Simpler handling of double chunked [RT#77240] - Check for timeouts before reading [RT#72676] - Fake can_read - -Dagfinn Ilmari Mannsåker (1): - Fix chunked decoding on temporary read error [RT#74431] - -Eric Wong (1): - NB: set http_bytes if read_entity_body hits EAGAIN on first read - -Jay Hannah (1): - chunked,chunked is invalid, but happens. :( Ignore all but the first. [RT#77240] - - - -_______________________________________________________________________________ -2012-02-16 Net-HTTP 6.03 - -Restore blocking override for Net::SSL [RT#72790] - -Restore perl-5.6 compatibility. - - -_______________________________________________________________________________ -2011-11-21 Net-HTTP 6.02 - -Don't disable blocking method [RT#72580] -Don't stop on unrecognized Makefile.PL arguments [RT#68337] -Document Net:HTTPS [RT#71599] - - - -_______________________________________________________________________________ -2011-03-17 Net-HTTP 6.01 - -Don't run live test by default. Run 'perl Makefile.PL --live-tests' to enable. -More relaxed apache test; should pass even if proxies has added headers. - - - -_______________________________________________________________________________ -2011-02-27 Net-HTTP 6.00 - -Initial release of Net-HTTP as a separate distribution. There are no code -changes besides incrementing the version number since libwww-perl-5.837. - -The Net::HTTP module used to be bundled with the libwww-perl distribution. + - Updated the Changes file + - When using Net::SSL, pending data was potentially ignored GH PR#7 + +6.10-DEV 2016-12-30 + - Added LICENSE + - Added 'use warnings' to everywhere that lacked it + - Drop all use of Test.pm + - Removed unneeded uses of 'use vars' + - Switch live tests to use Google. + - Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0 + +6.09 2015-05-20 + - No changes since 6.08_002 + +6.08_002 2015-05-02 + - Fix foolish $VERSION error in 6.08_001 (Karen Etheridge) + +6.08_001 2015-05-01 + - resolve issues with SSL by reading bytes still waiting to be read after + the initial 1024 bytes [RT#104122] (Mark Overmeer) + +6.07 2014-07-23 + - Opportunistically use IO::Socket::IP or IO::Socket::INET6. (Jason Fesler) + - Properly parse IPv6 literal addresses with optional port numbers. [RT#75618] + +6.06 2013-03-10 + - IO::Socket::SSL doesn't play well with select() [RT#81237] (Jesse Luehrs) + +6.05 2012-11-10 + - Convert to Test::More style and disable test on Windows [RT#81090] (Gisle Aas) + - SSL broken for some servers [RT#81073] (Marinos Yannikos) + +6.04 2012-11-08 + - Simpler handling of double chunked [RT#77240] (Gisle Aas) + - Check for timeouts before reading [RT#72676] (Gisle Aas) + - Fake can_read (Gisle Aas) + - Fix chunked decoding on temporary read error [RT#74431] (Dagfinn Ilmari Mannsåker) + - NB: set http_bytes if read_entity_body hits EAGAIN on first read (Eric Wong) + - chunked,chunked is invalid, but happens. Ignore all but the first. [RT#77240] (Jay Hannah) + +6.03 2012-02-16 + - Restore blocking override for Net::SSL [RT#72790] + - Restore perl-5.6 compatibility. + +6.02 2011-11-21 + - Don't disable blocking method [RT#72580] + - Don't stop on unrecognized Makefile.PL arguments [RT#68337] + - Document Net:HTTPS [RT#71599] + +6.01 2011-03-17 + - Don't run live test by default; 'perl Makefile.PL --live-tests' to enable. + - More relaxed apache test; should pass even if proxies has added headers. + +6.00 2011-02-27 + - Initial release of Net-HTTP as a separate distribution. + - No code changes. + - Version bump to be ahead of old release + - The Net::HTTP module used to be bundled with the libwww-perl distribution. From 5bed208198aa473cd158720a2dd402358dea2f71 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 4 Jan 2017 15:04:58 -0500 Subject: [PATCH 47/52] Updates Changes. --- Changes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes b/Changes index c4358766..fc8bc9e9 100644 --- a/Changes +++ b/Changes @@ -2,7 +2,7 @@ Release history for {{$dist->name}} {{$NEXT}} - Updated the Changes file - - When using Net::SSL, pending data was potentially ignored GH PR#7 + - When using Net::SSL, pending data was potentially ignored GH PR#7 (Jean-Louis Martineau) 6.10-DEV 2016-12-30 - Added LICENSE From 51785837ffce114939252a7dfc0c0a51b48fe14d Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 4 Jan 2017 15:06:14 -0500 Subject: [PATCH 48/52] v6.11 - Updated the Changes file - When using Net::SSL, pending data was potentially ignored GH PR#7 (Jean-Louis Martineau) --- Changes | 2 + LICENSE | 6 +- META.json | 6 +- Makefile.PL | 2 +- README.md | 338 ++++++++++++++++++++++++++-------------------------- dist.ini | 4 +- 6 files changed, 182 insertions(+), 176 deletions(-) diff --git a/Changes b/Changes index fc8bc9e9..bf783cea 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Release history for {{$dist->name}} {{$NEXT}} + +6.11 2017-01-04 15:05:57-05:00 America/Toronto - Updated the Changes file - When using Net::SSL, pending data was potentially ignored GH PR#7 (Jean-Louis Martineau) diff --git a/LICENSE b/LICENSE index a7d6970b..0df0e2e4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -This software is copyright (c) 2001-2016 by Gisle Aas. +This software is copyright (c) 2001-2017 by Gisle Aas. 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) 2001-2016 by Gisle Aas. +This software is Copyright (c) 2001-2017 by Gisle Aas. 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) 2001-2016 by Gisle Aas. +This software is Copyright (c) 2001-2017 by Gisle Aas. This is free software, licensed under: diff --git a/META.json b/META.json index 3191c392..0cea75eb 100644 --- a/META.json +++ b/META.json @@ -61,7 +61,7 @@ } } }, - "release_status" : "testing", + "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/libwww-perl/Net-HTTP/issues" @@ -75,7 +75,7 @@ "x_IRC" : "irc://irc.perl.org/#lwp", "x_MailingList" : "mailto:libwww@perl.org" }, - "version" : "6.10", + "version" : "6.11", "x_contributors" : [ "Adam Kennedy ", "Adam Sjogren ", @@ -86,6 +86,7 @@ "Andy Grundman ", "Bill Mann ", "Bron Gondwana ", + "Chase Whitener ", "Dagfinn Ilmari Manns\u00e5ker ", "Daniel Hedlund ", "David E. Wheeler ", @@ -105,6 +106,7 @@ "Jacob J ", "Jason A Fesler ", "Jay Hannah ", + "Jean-Louis Martineau ", "jefflee ", "Jesse Luehrs ", "john9art ", diff --git a/Makefile.PL b/Makefile.PL index b7e4f794..742cc150 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -39,7 +39,7 @@ my %WriteMakefileArgs = ( "Socket" => 0, "Test::More" => 0 }, - "VERSION" => "6.10", + "VERSION" => "6.11", "test" => { "TESTS" => "t/*.t" } diff --git a/README.md b/README.md index 9521fe6f..fe02915d 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,48 @@ -NAME +# NAME - Net::HTTP - Low-level HTTP connection (client) +Net::HTTP - Low-level HTTP connection (client) -VERSION +[![Build Status](https://travis-ci.org/libwww-perl/Net-HTTP.png?branch=master)](https://travis-ci.org/libwww-perl/Net-HTTP) - version 6.10 +# VERSION -SYNOPSIS +version 6.11 - use Net::HTTP; - my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; - $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); - my($code, $mess, %h) = $s->read_response_headers; - - while (1) { - my $buf; - my $n = $s->read_entity_body($buf, 1024); - die "read failed: $!" unless defined $n; - last unless $n; - print $buf; - } +# SYNOPSIS -DESCRIPTION + use Net::HTTP; + my $s = Net::HTTP->new(Host => "www.perl.com") || die $@; + $s->write_request(GET => "/", 'User-Agent' => "Mozilla/5.0"); + my($code, $mess, %h) = $s->read_response_headers; - The Net::HTTP class is a low-level HTTP client. An instance of the - Net::HTTP class represents a connection to an HTTP server. The HTTP - protocol is described in RFC 2616. The Net::HTTP class supports - HTTP/1.0 and HTTP/1.1. + while (1) { + my $buf; + my $n = $s->read_entity_body($buf, 1024); + die "read failed: $!" unless defined $n; + last unless $n; + print $buf; + } - Net::HTTP is a sub-class of one of IO::Socket::IP (IPv6+IPv4), - IO::Socket::INET6 (IPv6+IPv4), or IO::Socket::INET (IPv4 only). You can - mix the methods described below with reading and writing from the - socket directly. This is not necessary a good idea, unless you know - what you are doing. +# DESCRIPTION - The following methods are provided (in addition to those of - IO::Socket::INET): +The `Net::HTTP` class is a low-level HTTP client. An instance of the +`Net::HTTP` class represents a connection to an HTTP server. The +HTTP protocol is described in RFC 2616. The `Net::HTTP` class +supports `HTTP/1.0` and `HTTP/1.1`. - $s = Net::HTTP->new( %options ) +`Net::HTTP` is a sub-class of one of `IO::Socket::IP` (IPv6+IPv4), +`IO::Socket::INET6` (IPv6+IPv4), or `IO::Socket::INET` (IPv4 only). +You can mix the methods described below with reading and writing from the +socket directly. This is not necessary a good idea, unless you know what +you are doing. - The Net::HTTP constructor method takes the same options as - IO::Socket::INET's as well as these: +The following methods are provided (in addition to those of +`IO::Socket::INET`): + +- $s = Net::HTTP->new( %options ) + + The `Net::HTTP` constructor method takes the same options as + `IO::Socket::INET`'s as well as these: Host: Initial host attribute value KeepAlive: Initial keep_alive attribute value @@ -50,201 +52,201 @@ DESCRIPTION MaxLineLength: Initial max_line_length attribute value MaxHeaderLines: Initial max_header_lines attribute value - The Host option is also the default for IO::Socket::INET's PeerAddr. - The PeerPort defaults to 80 if not provided. The PeerPort - specification can also be embedded in the PeerAddr by preceding it - with a ":", and closing the IPv6 address on brackets "[]" if - necessary: "192.0.2.1:80","[2001:db8::1]:80","any.example.com:80". - - The Listen option provided by IO::Socket::INET's constructor method - is not allowed. + The `Host` option is also the default for `IO::Socket::INET`'s + `PeerAddr`. The `PeerPort` defaults to 80 if not provided. + The `PeerPort` specification can also be embedded in the `PeerAddr` + by preceding it with a ":", and closing the IPv6 address on brackets "\[\]" if + necessary: "192.0.2.1:80","\[2001:db8::1\]:80","any.example.com:80". - If unable to connect to the given HTTP server then the constructor - returns undef and $@ contains the reason. After a successful connect, - a Net:HTTP object is returned. + The `Listen` option provided by `IO::Socket::INET`'s constructor + method is not allowed. - $s->host + If unable to connect to the given HTTP server then the constructor + returns `undef` and $@ contains the reason. After a successful + connect, a `Net:HTTP` object is returned. - Get/set the default value of the Host header to send. The $host must - not be set to an empty string (or undef) for HTTP/1.1. +- $s->host - $s->keep_alive + Get/set the default value of the `Host` header to send. The $host + must not be set to an empty string (or `undef`) for HTTP/1.1. - Get/set the keep-alive value. If this value is TRUE then the request - will be sent with headers indicating that the server should try to - keep the connection open so that multiple requests can be sent. +- $s->keep\_alive - The actual headers set will depend on the value of the http_version - and peer_http_version attributes. + Get/set the _keep-alive_ value. If this value is TRUE then the + request will be sent with headers indicating that the server should try + to keep the connection open so that multiple requests can be sent. - $s->send_te + The actual headers set will depend on the value of the `http_version` + and `peer_http_version` attributes. - Get/set the a value indicating if the request will be sent with a - "TE" header to indicate the transfer encodings that the server can - choose to use. The list of encodings announced as accepted by this - client depends on availability of the following modules: - Compress::Raw::Zlib for deflate, and IO::Compress::Gunzip for gzip. +- $s->send\_te - $s->http_version + Get/set the a value indicating if the request will be sent with a "TE" + header to indicate the transfer encodings that the server can choose to + use. The list of encodings announced as accepted by this client depends + on availability of the following modules: `Compress::Raw::Zlib` for + _deflate_, and `IO::Compress::Gunzip` for _gzip_. - Get/set the HTTP version number that this client should announce. - This value can only be set to "1.0" or "1.1". The default is "1.1". +- $s->http\_version - $s->peer_http_version + Get/set the HTTP version number that this client should announce. + This value can only be set to "1.0" or "1.1". The default is "1.1". - Get/set the protocol version number of our peer. This value will - initially be "1.0", but will be updated by a successful - read_response_headers() method call. +- $s->peer\_http\_version - $s->max_line_length + Get/set the protocol version number of our peer. This value will + initially be "1.0", but will be updated by a successful + read\_response\_headers() method call. - Get/set a limit on the length of response line and response header - lines. The default is 8192. A value of 0 means no limit. +- $s->max\_line\_length - $s->max_header_length + Get/set a limit on the length of response line and response header + lines. The default is 8192. A value of 0 means no limit. - Get/set a limit on the number of header lines that a response can - have. The default is 128. A value of 0 means no limit. +- $s->max\_header\_length - $s->format_request($method, $uri, %headers, [$content]) + Get/set a limit on the number of header lines that a response can + have. The default is 128. A value of 0 means no limit. - Format a request message and return it as a string. If the headers do - not include a Host header, then a header is inserted with the value - of the host attribute. Headers like Connection and Keep-Alive might - also be added depending on the status of the keep_alive attribute. +- $s->format\_request($method, $uri, %headers, \[$content\]) - If $content is given (and it is non-empty), then a Content-Length - header is automatically added unless it was already present. + Format a request message and return it as a string. If the headers do + not include a `Host` header, then a header is inserted with the value + of the `host` attribute. Headers like `Connection` and + `Keep-Alive` might also be added depending on the status of the + `keep_alive` attribute. - $s->write_request($method, $uri, %headers, [$content]) + If $content is given (and it is non-empty), then a `Content-Length` + header is automatically added unless it was already present. - Format and send a request message. Arguments are the same as for - format_request(). Returns true if successful. +- $s->write\_request($method, $uri, %headers, \[$content\]) - $s->format_chunk( $data ) + Format and send a request message. Arguments are the same as for + format\_request(). Returns true if successful. - Returns the string to be written for the given chunk of data. +- $s->format\_chunk( $data ) - $s->write_chunk($data) + Returns the string to be written for the given chunk of data. - Will write a new chunk of request entity body data. This method - should only be used if the Transfer-Encoding header with a value of - chunked was sent in the request. Note, writing zero-length data is a - no-op. Use the write_chunk_eof() method to signal end of entity body - data. +- $s->write\_chunk($data) - Returns true if successful. + Will write a new chunk of request entity body data. This method + should only be used if the `Transfer-Encoding` header with a value of + `chunked` was sent in the request. Note, writing zero-length data is + a no-op. Use the write\_chunk\_eof() method to signal end of entity + body data. - $s->format_chunk_eof( %trailers ) + Returns true if successful. - Returns the string to be written for signaling EOF when a - Transfer-Encoding of chunked is used. +- $s->format\_chunk\_eof( %trailers ) - $s->write_chunk_eof( %trailers ) + Returns the string to be written for signaling EOF when a + `Transfer-Encoding` of `chunked` is used. - Will write eof marker for chunked data and optional trailers. Note - that trailers should not really be used unless is was signaled with a - Trailer header. +- $s->write\_chunk\_eof( %trailers ) - Returns true if successful. + Will write eof marker for chunked data and optional trailers. Note + that trailers should not really be used unless is was signaled + with a `Trailer` header. - ($code, $mess, %headers) = $s->read_response_headers( %opts ) + Returns true if successful. - Read response headers from server and return it. The $code is the 3 - digit HTTP status code (see HTTP::Status) and $mess is the textual - message that came with it. Headers are then returned as key/value - pairs. Since key letter casing is not normalized and the same key can - even occur multiple times, assigning these values directly to a hash - is not wise. Only the $code is returned if this method is called in - scalar context. +- ($code, $mess, %headers) = $s->read\_response\_headers( %opts ) - As a side effect this method updates the 'peer_http_version' - attribute. + Read response headers from server and return it. The $code is the 3 + digit HTTP status code (see [HTTP::Status](https://metacpan.org/pod/HTTP::Status)) and $mess is the textual + message that came with it. Headers are then returned as key/value + pairs. Since key letter casing is not normalized and the same key can + even occur multiple times, assigning these values directly to a hash + is not wise. Only the $code is returned if this method is called in + scalar context. - Options might be passed in as key/value pairs. There are currently - only two options supported; laxed and junk_out. + As a side effect this method updates the 'peer\_http\_version' + attribute. - The laxed option will make read_response_headers() more forgiving - towards servers that have not learned how to speak HTTP properly. The - laxed option is a boolean flag, and is enabled by passing in a TRUE - value. The junk_out option can be used to capture bad header lines - when laxed is enabled. The value should be an array reference. Bad - header lines will be pushed onto the array. + Options might be passed in as key/value pairs. There are currently + only two options supported; `laxed` and `junk_out`. - The laxed option must be specified in order to communicate with - pre-HTTP/1.0 servers that don't describe the response outcome or the - data they send back with a header block. For these servers - peer_http_version is set to "0.9" and this method returns (200, - "Assumed OK"). + The `laxed` option will make read\_response\_headers() more forgiving + towards servers that have not learned how to speak HTTP properly. The + `laxed` option is a boolean flag, and is enabled by passing in a TRUE + value. The `junk_out` option can be used to capture bad header lines + when `laxed` is enabled. The value should be an array reference. + Bad header lines will be pushed onto the array. - The method will raise an exception (die) if the server does not speak - proper HTTP or if the max_line_length or max_header_length limits are - reached. If the laxed option is turned on and max_line_length and - max_header_length checks are turned off, then no exception will be - raised and this method will always return a response code. + The `laxed` option must be specified in order to communicate with + pre-HTTP/1.0 servers that don't describe the response outcome or the + data they send back with a header block. For these servers + peer\_http\_version is set to "0.9" and this method returns (200, + "Assumed OK"). - $n = $s->read_entity_body($buf, $size); + The method will raise an exception (die) if the server does not speak + proper HTTP or if the `max_line_length` or `max_header_length` + limits are reached. If the `laxed` option is turned on and + `max_line_length` and `max_header_length` checks are turned off, + then no exception will be raised and this method will always + return a response code. - Reads chunks of the entity body content. Basically the same interface - as for read() and sysread(), but the buffer offset argument is not - supported yet. This method should only be called after a successful - read_response_headers() call. +- $n = $s->read\_entity\_body($buf, $size); - The return value will be undef on read errors, 0 on EOF, -1 if no - data could be returned this time, otherwise the number of bytes - assigned to $buf. The $buf is set to "" when the return value is -1. + Reads chunks of the entity body content. Basically the same interface + as for read() and sysread(), but the buffer offset argument is not + supported yet. This method should only be called after a successful + read\_response\_headers() call. - You normally want to retry this call if this function returns either - -1 or undef with $! as EINTR or EAGAIN (see Errno). EINTR can happen - if the application catches signals and EAGAIN can happen if you made - the socket non-blocking. + The return value will be `undef` on read errors, 0 on EOF, -1 if no data + could be returned this time, otherwise the number of bytes assigned + to $buf. The $buf is set to "" when the return value is -1. - This method will raise exceptions (die) if the server does not speak - proper HTTP. This can only happen when reading chunked data. + You normally want to retry this call if this function returns either + \-1 or `undef` with `$!` as EINTR or EAGAIN (see [Errno](https://metacpan.org/pod/Errno)). EINTR + can happen if the application catches signals and EAGAIN can happen if + you made the socket non-blocking. - %headers = $s->get_trailers + This method will raise exceptions (die) if the server does not speak + proper HTTP. This can only happen when reading chunked data. - After read_entity_body() has returned 0 to indicate end of the entity - body, you might call this method to pick up any trailers. +- %headers = $s->get\_trailers - $s->_rbuf + After read\_entity\_body() has returned 0 to indicate end of the entity + body, you might call this method to pick up any trailers. - Get/set the read buffer content. The read_response_headers() and - read_entity_body() methods use an internal buffer which they will - look for data before they actually sysread more from the socket - itself. If they read too much, the remaining data will be left in - this buffer. +- $s->\_rbuf - $s->_rbuf_length + Get/set the read buffer content. The read\_response\_headers() and + read\_entity\_body() methods use an internal buffer which they will look + for data before they actually sysread more from the socket itself. If + they read too much, the remaining data will be left in this buffer. - Returns the number of bytes in the read buffer. This should always be - the same as: +- $s->\_rbuf\_length - length($s->_rbuf) + Returns the number of bytes in the read buffer. This should always be + the same as: - but might be more efficient. + length($s->_rbuf) -SUBCLASSING + but might be more efficient. - The read_response_headers() and read_entity_body() will invoke the - sysread() method when they need more data. Subclasses might want to - override this method to control how reading takes place. +# SUBCLASSING - The object itself is a glob. Subclasses should avoid using hash key - names prefixed with http_ and io_. +The read\_response\_headers() and read\_entity\_body() will invoke the +sysread() method when they need more data. Subclasses might want to +override this method to control how reading takes place. -SEE ALSO +The object itself is a glob. Subclasses should avoid using hash key +names prefixed with `http_` and `io_`. - LWP, IO::Socket::INET, Net::HTTP::NB +# SEE ALSO -AUTHOR +[LWP](https://metacpan.org/pod/LWP), [IO::Socket::INET](https://metacpan.org/pod/IO::Socket::INET), [Net::HTTP::NB](https://metacpan.org/pod/Net::HTTP::NB) - Gisle Aas +# AUTHOR -COPYRIGHT AND LICENSE +Gisle Aas - This software is copyright (c) 2001-2016 by Gisle Aas. +# COPYRIGHT AND LICENSE - This is free software; you can redistribute it and/or modify it under - the same terms as the Perl 5 programming language system itself. +This software is copyright (c) 2001-2017 by Gisle Aas. +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. diff --git a/dist.ini b/dist.ini index 8fac3a6d..eef9e220 100644 --- a/dist.ini +++ b/dist.ini @@ -3,8 +3,8 @@ author = Gisle Aas license = Perl_5 main_module = lib/Net/HTTP.pm copyright_holder = Gisle Aas -copyright_year = 2001-2016 -version = 6.10 +copyright_year = 2001-2017 +version = 6.11 [MetaResources] x_IRC = irc://irc.perl.org/#lwp From 9c87ea6d0b99e3e64f4f559f0abed8661dd2db72 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 4 Jan 2017 18:16:56 -0500 Subject: [PATCH 49/52] Soften prereqs. --- META.json | 14 ++++++-------- Makefile.PL | 14 +------------- README.md | 2 +- cpanfile | 10 ++++------ dist.ini | 20 ++++++++++++++++---- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/META.json b/META.json index 0cea75eb..cd592f75 100644 --- a/META.json +++ b/META.json @@ -31,19 +31,17 @@ }, "runtime" : { "recommends" : { - "IO::Socket::SSL" : "1.38" + "IO::Socket" : "0", + "IO::Socket::INET6" : "0", + "IO::Socket::IP" : "0", + "IO::Socket::SSL" : "1.38", + "Symbol" : "0" }, "requires" : { "Carp" : "0", "Compress::Raw::Zlib" : "0", - "IO::Socket" : "0", "IO::Socket::INET" : "0", - "IO::Socket::INET6" : "0", - "IO::Socket::IP" : "0", - "IO::Socket::SSL" : "0", "IO::Uncompress::Gunzip" : "0", - "Net::SSL" : "0", - "Symbol" : "0", "URI" : "0", "base" : "0", "perl" : "5.006002", @@ -75,7 +73,7 @@ "x_IRC" : "irc://irc.perl.org/#lwp", "x_MailingList" : "mailto:libwww@perl.org" }, - "version" : "6.11", + "version" : "6.12", "x_contributors" : [ "Adam Kennedy ", "Adam Sjogren ", diff --git a/Makefile.PL b/Makefile.PL index 742cc150..13a33b73 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,14 +19,8 @@ my %WriteMakefileArgs = ( "PREREQ_PM" => { "Carp" => 0, "Compress::Raw::Zlib" => 0, - "IO::Socket" => 0, "IO::Socket::INET" => 0, - "IO::Socket::INET6" => 0, - "IO::Socket::IP" => 0, - "IO::Socket::SSL" => 0, "IO::Uncompress::Gunzip" => 0, - "Net::SSL" => 0, - "Symbol" => 0, "URI" => 0, "base" => 0, "strict" => 0, @@ -39,7 +33,7 @@ my %WriteMakefileArgs = ( "Socket" => 0, "Test::More" => 0 }, - "VERSION" => "6.11", + "VERSION" => "6.12", "test" => { "TESTS" => "t/*.t" } @@ -51,15 +45,9 @@ my %FallbackPrereqs = ( "Compress::Raw::Zlib" => 0, "Data::Dumper" => 0, "IO::Select" => 0, - "IO::Socket" => 0, "IO::Socket::INET" => 0, - "IO::Socket::INET6" => 0, - "IO::Socket::IP" => 0, - "IO::Socket::SSL" => 0, "IO::Uncompress::Gunzip" => 0, - "Net::SSL" => 0, "Socket" => 0, - "Symbol" => 0, "Test::More" => 0, "URI" => 0, "base" => 0, diff --git a/README.md b/README.md index fe02915d..5b7e49eb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Net::HTTP - Low-level HTTP connection (client) # VERSION -version 6.11 +version 6.12 # SYNOPSIS diff --git a/cpanfile b/cpanfile index d6e73fb1..409fb191 100644 --- a/cpanfile +++ b/cpanfile @@ -1,20 +1,18 @@ requires "Carp" => "0"; requires "Compress::Raw::Zlib" => "0"; -requires "IO::Socket" => "0"; requires "IO::Socket::INET" => "0"; -requires "IO::Socket::INET6" => "0"; -requires "IO::Socket::IP" => "0"; -requires "IO::Socket::SSL" => "0"; requires "IO::Uncompress::Gunzip" => "0"; -requires "Net::SSL" => "0"; -requires "Symbol" => "0"; requires "URI" => "0"; requires "base" => "0"; requires "perl" => "5.006002"; requires "strict" => "0"; requires "vars" => "0"; requires "warnings" => "0"; +recommends "IO::Socket" => "0"; +recommends "IO::Socket::INET6" => "0"; +recommends "IO::Socket::IP" => "0"; recommends "IO::Socket::SSL" => "1.38"; +recommends "Symbol" => "0"; on 'test' => sub { requires "Data::Dumper" => "0"; diff --git a/dist.ini b/dist.ini index eef9e220..da5d16af 100644 --- a/dist.ini +++ b/dist.ini @@ -4,7 +4,7 @@ license = Perl_5 main_module = lib/Net/HTTP.pm copyright_holder = Gisle Aas copyright_year = 2001-2017 -version = 6.11 +version = 6.12 [MetaResources] x_IRC = irc://irc.perl.org/#lwp @@ -13,10 +13,8 @@ x_MailingList = mailto:libwww@perl.org [Prereqs] perl = 5.006002 -[Prereqs / RuntimeRecommends] -IO::Socket::SSL = 1.38 - [@Author::OALDERS] +-remove = AutoPrereqs -remove = CheckChangesHasContent -remove = MinimumPerl -remove = PodCoverageTests @@ -26,3 +24,17 @@ IO::Socket::SSL = 1.38 -remove = Test::PodSpelling -remove = Test::Synopsis -remove = Test::TidyAll + +[AutoPrereqs] +skip = Net::SSL + +[Prereqs / RuntimeRecommends] +IO::Socket::SSL = 1.38 + +[Prereqs::Soften] +to_relationship = recommends +module = IO::Socket +module = IO::Socket::INET6 +module = IO::Socket::IP +module = IO::Socket::SSL +module = Symbol From b8f42fb92665f0f61862107e53cfe8d9b6bf69c6 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 4 Jan 2017 18:37:01 -0500 Subject: [PATCH 50/52] s/recommends/suggests/ --- META.json | 14 +++++++------- cpanfile | 10 +++++----- dist.ini | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/META.json b/META.json index cd592f75..33f046ca 100644 --- a/META.json +++ b/META.json @@ -30,13 +30,6 @@ } }, "runtime" : { - "recommends" : { - "IO::Socket" : "0", - "IO::Socket::INET6" : "0", - "IO::Socket::IP" : "0", - "IO::Socket::SSL" : "1.38", - "Symbol" : "0" - }, "requires" : { "Carp" : "0", "Compress::Raw::Zlib" : "0", @@ -48,6 +41,13 @@ "strict" : "0", "vars" : "0", "warnings" : "0" + }, + "suggests" : { + "IO::Socket" : "0", + "IO::Socket::INET6" : "0", + "IO::Socket::IP" : "0", + "IO::Socket::SSL" : "1.38", + "Symbol" : "0" } }, "test" : { diff --git a/cpanfile b/cpanfile index 409fb191..9306626e 100644 --- a/cpanfile +++ b/cpanfile @@ -8,11 +8,11 @@ requires "perl" => "5.006002"; requires "strict" => "0"; requires "vars" => "0"; requires "warnings" => "0"; -recommends "IO::Socket" => "0"; -recommends "IO::Socket::INET6" => "0"; -recommends "IO::Socket::IP" => "0"; -recommends "IO::Socket::SSL" => "1.38"; -recommends "Symbol" => "0"; +suggests "IO::Socket" => "0"; +suggests "IO::Socket::INET6" => "0"; +suggests "IO::Socket::IP" => "0"; +suggests "IO::Socket::SSL" => "1.38"; +suggests "Symbol" => "0"; on 'test' => sub { requires "Data::Dumper" => "0"; diff --git a/dist.ini b/dist.ini index da5d16af..b6517a84 100644 --- a/dist.ini +++ b/dist.ini @@ -28,11 +28,11 @@ perl = 5.006002 [AutoPrereqs] skip = Net::SSL -[Prereqs / RuntimeRecommends] +[Prereqs / RuntimeSuggests] IO::Socket::SSL = 1.38 [Prereqs::Soften] -to_relationship = recommends +to_relationship = suggests module = IO::Socket module = IO::Socket::INET6 module = IO::Socket::IP From 441540f7e97e05d36a9192a43fb2d5775bd1cad0 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 4 Jan 2017 23:33:35 -0500 Subject: [PATCH 51/52] v6.12 - Fix prereqs --- Changes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changes b/Changes index bf783cea..02db50ed 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Release history for {{$dist->name}} {{$NEXT}} +6.12 2017-01-04 23:32:54-05:00 America/Toronto + - Fix prereqs + 6.11 2017-01-04 15:05:57-05:00 America/Toronto - Updated the Changes file - When using Net::SSL, pending data was potentially ignored GH PR#7 (Jean-Louis Martineau) From 8a98c430f0ad3ae1893b4874dc6146d362cfd4fa Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Thu, 16 Feb 2017 17:17:42 -0600 Subject: [PATCH 52/52] Fix small typo in Changes --- Changes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes b/Changes index 02db50ed..bd95b5a0 100644 --- a/Changes +++ b/Changes @@ -15,7 +15,7 @@ Release history for {{$dist->name}} - Drop all use of Test.pm - Removed unneeded uses of 'use vars' - Switch live tests to use Google. - - Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $reponse_size % 1024 == 0 + - Fix RT#112313 - Hang in my_readline() when keep-alive => 1 and $response_size % 1024 == 0 6.09 2015-05-20 - No changes since 6.08_002