File-HTTP
view release on metacpan or search on metacpan
- $MAX_LENGTH_SKIP default value increased from 16KB to 256KB
- updated to Module::Install 1.19
0.91 2013-08-28
- get(): returns '502' response headers when none was received
0.90 2013-08-27
- get() function added
- retries connection on signal interruption
- SSL_verify_mode explicitely set to SSL_VERIFY_NONE in
IO::Socket::SSL constructor arguments
- $MAX_LENGTH_SKIP default value reduced from 128KB to 16KB
0.89 2012-10-22
- update to Module::Install 1.06 following Tatsuhiko
Miyagawafor's recommandation for perl 5.16 compatibility:
http://weblog.bulknews.net/post/33907905561/do-not-ship-modules-with-module-install-1-04
0.88 2012-03-21
- protocol redirection handling
- minor POD clarifications
0.872 2012-02-16
- forgot to actually _save_ the new makefile...
- some more fixes in POD
0.871 2012-02-16
- requires constant 1.03 (multiple constant definition,
form perl 5.7.2)
- minor POD fixes (still much to be done, sorry for that
poor doc and tests...)
- recommands IO::Socket::SSL and Time::y2038 in makefile
0.87 2012-02-14
- First release on CPAN (module in use since 2009)
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: File-HTTP
no_index:
directory:
- inc
- t
recommends:
IO::Socket::SSL: 0
Time::y2038: 0
requires:
constant: 1.03
resources:
license: http://dev.perl.org/licenses/
version: 1.11
Makefile.PL view on Meta::CPAN
use inc::Module::Install;
name 'File-HTTP';
all_from 'lib/File/HTTP.pm';
build_requires 'Test::More' => '0.42';
requires 'constant' => '1.03';
recommends 'IO::Socket::SSL' => 0;
recommends 'Time::y2038' => 0;
WriteAll;
lib/File/HTTP.pm view on Meta::CPAN
use Socket ();
use Errno ();
use Fcntl ();
use Exporter;
use bytes ();
use Time::HiRes qw(time);
use constant 1.03; # hash ref, perl 5.7.2
# on demand modules:
# - Time::y2038 or Time::Local
# - IO::Socket::SSL
our $VERSION = '1.11';
our @EXPORT_OK = qw(
open stat open_at open_stream slurp_stream get post
opendir readdir rewinddir telldir seekdir closedir
opendir_slash
_e _s
);
lib/File/HTTP.pm view on Meta::CPAN
}
last if $status;
die $! unless $_ < 3 && $! =~ /Interrupted system call/i;
}
$self->[FH_STAT] ||= [ CORE::stat($self->[FH]) ];
if ($self->[PROTO] eq 'HTTPS') {
$self->[SSL] = 1;
unless ($SSL_LOADED) {
eval {require IO::Socket::SSL;1} || croak "HTTPS support requires IO::Socket::SSL: $@";
$SSL_LOADED = 1;
}
if ($self->[CONNECT_NETLOC]) {
my ($code, $headers) = $self->_handshake(
join("\015\012",
"CONNECT $self->[CONNECT_NETLOC] HTTP/1.0",
"User-Agent: ". ($TUNNELING_USER_AGENT||$USER_AGENT),
'',
''
)
);
die "error: HTTP error $code from proxy during CONNECT\n" unless $code == 200;
}
IO::Socket::SSL->start_SSL($self->[FH],
SSL_verifycn_name => $self->[REMOTE_HOST],
SSL_hostname => $self->[REMOTE_HOST],
SSL_session_cache_size => 100,
SSL_verify_mode => &IO::Socket::SSL::SSL_VERIFY_NONE,
);
}
(my $code, $RESPONSE_HEADERS) = $self->_handshake($REQUEST_HEADERS);
$self->[RESPONSE_TIME] = time;
my $code_ok = do {
if (defined $self->[OFFSET]) {
$code == 206
lib/File/HTTP.pm view on Meta::CPAN
($self->[LAST_MODIFIED]) = $RESPONSE_HEADERS =~ m!\015?\012Last-Modified: +([^\015\012]+)!i;
}
return unless defined $self->[OFFSET];
$self->[LAST_READ] = $self->[RESPONSE_TIME];
$self->[CURRENT_OFFSET] = $self->[OFFSET];
return 1;
}
# read() reimplementation to overcome IO::Socket::SSL behavior of read() acting as sysread()
# <> is ok though
sub _read {
my ($self, undef, $len, $off) = @_;
if (not defined $off) {
$off = 0;
}
elsif ($off < 0) {
$off += bytes::length($_[1])
}
my $n = read($self->[FH], $_[1], $len, $off);
return $n unless $n;
if ($self->[SSL] && $len && $n < $len) {
# strange IO::Socket::SSL behavior: read() acts as sysread()
while ($n < $len) {
my $n_part = read($self->[FH], $_[1], $len-$n, $off+$n);
return $n unless $n_part;
$n += $n_part;
}
}
return $n;
}
lib/File/HTTP.pod view on Meta::CPAN
seek($fh, 500, 0);
read($fh, my $buf, 40);
seek($fh, -40, 1);
read($fh, my $buf2, 40);
# $/ behaves as with regular files
local $/ = \52;
$buf = <$fh>;
# also works with https addresses if IO::Socket::SSL is available
open(my $fh, '<', 'https://example.com/robots.txt') or die $!;
# open() still works as expected with local files
open(my $fh, '<', "local_file") or die $!;
# directory (when servers allow directory listing)
use File::HTTP qw(:opendir);
opendir(my $dirh, 'http://example.com/files/') or die $!;
lib/File/HTTP.pod view on Meta::CPAN
C<opendir> only works with remote web servers and ressources that allow directory
listing, and list files as a simple <a href> links.
=back
=head1 OPTIONAL MODULES
=over 4
=item * L<IO::Socket::SSL> is required for HTTPS URLs
=item * Either L<Time::y2038> or L<Time::Local> will be used to set the modification
date in state
=back
=head1 TODO
=over 4
( run in 0.374 second using v1.01-cache-2.11-cpan-05444aca049 )