Commit 481ab574 authored by Alessandro Ghedini's avatar Alessandro Ghedini

[svn-inject] Installing original source of libhttp-tiny-perl (0.007)

parents
Release notes for HTTP-Tiny
0.007 2011-01-12 04:56:16 EST5EDT
- Added support for redirecting 303 and 307 response codes
- Retry (once) a request that fails due to a closed socket
(per RFC2616 8.1.4)
- Automatically sets request Content-Type to 'application/octet-stream'
if there is content the user has not defined its type
- Trailing headers from chunked transfer encoding are now merged
into the response headers instead of ignored
- Improved handling of malformed or unsupported HTTP protocols
- Expanded http:///.../ as http://localhost/.../ and set Host header
- Documented that URL's must be escaped/encoded
- Documented that the headers hash option may contain an array reference
to output multiple values of the same header field
- Improved documentation of limitations
- Added numerous new tests to ensure compliance with the HTTP/1.1 spec
0.006 2011-01-10 07:28:11 EST5EDT
- Transfer-Encodings are case insensitive
- Add additional test for proper behavior when both Content-Length
and Transfer-Encoding headers are received
0.005 2011-01-08 06:32:05 EST5EDT
- Fixed bug getting content for servers which do not sent Content-Length
- Add test coverage for get(), mirror() and request()
- Add test coverage for requests with static and generated content
0.004 2010-12-15 22:53:59 EST5EDT
- Renamed 'ok' response field to 'success'
- Handle all required HTTP/1.1 date formats
- Documented how callbacks are supposed to work
0.003 2010-12-15 12:30:42 EST5EDT
- Added 'ok' response field to simplify checking success
- Added a 'mirror' method mirror content to a file, but shortcut
if not modified
0.002 2010-12-13 21:59:39 EST5EDT
- Added some initial documentation
- Skips utf8::* code on Perls older than 5.8
0.001 2010-12-11 07:59:16 EST5EDT
- Initial CPAN release
This diff is collapsed.
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
dist.ini
eg/get.pl
eg/mirror.pl
lib/HTTP/Tiny.pm
t/00-compile.t
t/000_load.t
t/001_api.t
t/002_croakage.t
t/010_url.t
t/020_headers.t
t/030_response.t
t/040_content.t
t/050_chunked_body.t
t/060_http_date.t
t/100_get.t
t/110_mirror.t
t/120_put.t
t/130_redirect.t
t/200_live.t
t/Util.pm
t/cases/get-01.txt
t/cases/get-02.txt
t/cases/get-03.txt
t/cases/get-04.txt
t/cases/get-05.txt
t/cases/get-06.txt
t/cases/get-07.txt
t/cases/get-08.txt
t/cases/get-09.txt
t/cases/get-10.txt
t/cases/get-11.txt
t/cases/get-12.txt
t/cases/get-13.txt
t/cases/get-14.txt
t/cases/get-15.txt
t/cases/get-16.txt
t/cases/get-17.txt
t/cases/get-18.txt
t/cases/get-19.txt
t/cases/get-20.txt
t/cases/get-21.txt
t/cases/mirror-01.txt
t/cases/mirror-02.txt
t/cases/mirror-03.txt
t/cases/mirror-04.txt
t/cases/mirror-05.txt
t/cases/put-01.txt
t/cases/put-02.txt
t/cases/put-03.txt
t/cases/put-04.txt
t/cases/redirect-01.txt
t/cases/redirect-02.txt
t/cases/redirect-03.txt
t/cases/redirect-04.txt
t/cases/redirect-05.txt
t/cases/redirect-06.txt
t/cases/redirect-07.txt
t/cases/redirect-08.txt
t/cases/redirect-09.txt
xt/release/distmeta.t
xt/release/pod-coverage.t
xt/release/pod-syntax.t
xt/release/portability.t
{
"abstract" : "A small, simple, correct HTTP/1.1 client",
"author" : [
"Christian Hansen <chansen@cpan.org>",
"David Golden <dagolden@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 4.200001, CPAN::Meta::Converter version 2.102400",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "HTTP-Tiny",
"no_index" : {
"directory" : [
"t",
"xt",
"examples",
"corpus"
],
"package" : [
"DB"
]
},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.31"
}
},
"runtime" : {
"requires" : {
"Carp" : 0,
"Errno" : 0,
"IO::Socket" : 0,
"Time::Local" : 0,
"perl" : "5.006"
}
},
"test" : {
"requires" : {
"Exporter" : 0,
"File::Basename" : 0,
"File::Find" : 0,
"File::Temp" : 0,
"IO::Dir" : 0,
"IO::File" : 0,
"IO::Socket::INET" : 0,
"Test::More" : "0.88"
}
}
},
"provides" : {
"HTTP::Tiny" : {
"file" : "lib/HTTP/Tiny.pm",
"version" : "0.007"
},
"HTTP::Tiny::Handle" : {
"file" : "lib/HTTP/Tiny.pm",
"version" : "0.007"
}
},
"release_status" : "stable",
"resources" : {
"homepage" : "http://github.com/dagolden/p5-http-tiny/tree",
"repository" : {
"type" : "git",
"url" : "git://github.com/dagolden/p5-http-tiny.git",
"web" : "http://github.com/dagolden/p5-http-tiny/tree"
}
},
"version" : "0.007"
}
---
abstract: 'A small, simple, correct HTTP/1.1 client'
author:
- 'Christian Hansen <chansen@cpan.org>'
- 'David Golden <dagolden@cpan.org>'
build_requires:
Exporter: 0
File::Basename: 0
File::Find: 0
File::Temp: 0
IO::Dir: 0
IO::File: 0
IO::Socket::INET: 0
Test::More: 0.88
configure_requires:
ExtUtils::MakeMaker: 6.31
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.200001, CPAN::Meta::Converter version 2.102400'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: HTTP-Tiny
no_index:
directory:
- t
- xt
- examples
- corpus
package:
- DB
provides:
HTTP::Tiny:
file: lib/HTTP/Tiny.pm
version: 0.007
HTTP::Tiny::Handle:
file: lib/HTTP/Tiny.pm
version: 0.007
requires:
Carp: 0
Errno: 0
IO::Socket: 0
Time::Local: 0
perl: 5.006
resources:
homepage: http://github.com/dagolden/p5-http-tiny/tree
repository: git://github.com/dagolden/p5-http-tiny.git
version: 0.007
use strict;
use warnings;
BEGIN { require 5.006; }
use ExtUtils::MakeMaker 6.31;
my %WriteMakefileArgs = (
'ABSTRACT' => 'A small, simple, correct HTTP/1.1 client',
'AUTHOR' => 'Christian Hansen <chansen@cpan.org>, David Golden <dagolden@cpan.org>',
'BUILD_REQUIRES' => {
'Exporter' => '0',
'File::Basename' => '0',
'File::Find' => '0',
'File::Temp' => '0',
'IO::Dir' => '0',
'IO::File' => '0',
'IO::Socket::INET' => '0',
'Test::More' => '0.88'
},
'CONFIGURE_REQUIRES' => {
'ExtUtils::MakeMaker' => '6.31'
},
'DISTNAME' => 'HTTP-Tiny',
'EXE_FILES' => [],
'LICENSE' => 'perl',
'NAME' => 'HTTP::Tiny',
'PREREQ_PM' => {
'Carp' => '0',
'Errno' => '0',
'IO::Socket' => '0',
'Time::Local' => '0'
},
'VERSION' => '0.007',
'test' => {
'TESTS' => 't/*.t'
}
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
my $pp = $WriteMakefileArgs{PREREQ_PM};
for my $mod ( keys %$br ) {
if ( exists $pp->{$mod} ) {
$pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
}
else {
$pp->{$mod} = $br->{$mod};
}
}
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
NAME
HTTP::Tiny - A small, simple, correct HTTP/1.1 client
VERSION
version 0.007
SYNOPSIS
use HTTP::Tiny;
my $response = HTTP::Tiny->new->get('http://example.com/');
die "Failed!\n" unless $response->{success};
print "$response->{status} $response->{reason}\n";
while (my ($k, $v) = each %{$response->{headers}}) {
for (ref $v eq 'ARRAY' ? @$v : $v) {
print "$k: $_\n";
}
}
print $response->{content} if length $response->{content};
DESCRIPTION
This is a very simple HTTP/1.1 client, designed primarily for doing
simple GET requests without the overhead of a large framework like
LWP::UserAgent.
It is more correct and more complete than HTTP::Lite. It supports
proxies (currently only non-authenticating ones) and redirection. It
also correctly resumes after EINTR.
METHODS
new
$http = HTTP::Tiny->new( %attributes );
This constructor returns a new HTTP::Tiny object. Valid attributes
include:
* agent
A user-agent string (defaults to 'HTTP::Tiny/$VERSION')
* default_headers
A hashref of default headers to apply to requests
* max_redirect
Maximum number of redirects allowed (defaults to 5)
* max_size
Maximum response size (only when not using a data callback). If
defined, responses larger than this will die with an error message
* proxy
URL of a proxy server to use.
* timeout
Request timeout in seconds (default is 60)
get
$response = $http->get($url);
$response = $http->get($url, \%options);
Executes a "GET" request for the given URL. The URL must have unsafe
characters escaped and international domain names encoded. Internally,
it just calls "request()" with 'GET' as the method. See "request()" for
valid options and a description of the response.
mirror
$response = $http->mirror($url, $file, \%options)
if ( $response->{success} ) {
print "$file is up to date\n";
}
Executes a "GET" request for the URL and saves the response body to the
file name provided. The URL must have unsafe characters escaped and
international domain names encoded. If the file already exists, the
request will includes an "If-Modified-Since" header with the
modification timestamp of the file. You may specificy a different
"If-Modified-Since" header yourself in the "$options->{headers}" hash.
The "success" field of the response will be true if the status code is
2XX or 304 (unmodified).
If the file was modified and the server response includes a properly
formatted "Last-Modified" header, the file modification time will be
updated accordingly.
request
$response = $http->request($method, $url);
$response = $http->request($method, $url, \%options);
Executes an HTTP request of the given method type ('GET', 'HEAD', 'PUT',
etc.) on the given URL. The URL must have unsafe characters escaped and
international domain names encoded. A hashref of options may be appended
to modify the request.
Valid options are:
* headers
A hashref containing headers to include with the request. If the
value for a header is an array reference, the header will be output
multiple times with each value in the array. These headers
over-write any default headers.
* content
A scalar to include as the body of the request OR a code reference
that will be called iteratively to produce the body of the response
* data_callback
A code reference that will be called with chunks of the response
body
If the "content" option is a code reference, it will be called
iteratively to provide the content body of the request. It should return
the empty string or undef when the iterator is exhausted.
If the "data_callback" option is provided, it will be called iteratively
with a chunk of response body data as the sole argument until the entire
response body is received.
The "response" method returns a hashref containing the response. The
hashref will have the following keys:
* success
Boolean indicating whether the operation returned a 2XX status code
* status
The HTTP status code of the response
* reason
The response phrase returned by the server
* content
The body of the response. If the response does not have any content
or if a data callback is provided to consume the response body, this
will be the empty string
* headers
A hashref of header fields. All header field names will be
normalized to be lower case. If a header is repeated, the value will
be an arrayref; it will otherwise be a scalar string containing the
value
On an exception during the execution of the request, the "status" field
will contain 599, and the "content" field will contain the text of the
exception.
LIMITATIONS
HTTP::Tiny is *conditionally compliant* with the HTTP/1.1 specification
<http://www.w3.org/Protocols/rfc2616/rfc2616.html>. It attempts to meet
all "MUST" requirements of the specification, but does not implement all
"SHOULD" requirements.
Some particular limitations of note include:
* HTTP::Tiny focuses on correct transport. Users are responsible for
ensuring that user-defined headers and content are compliant with
the HTTP/1.1 specification.
* Users must ensure that URLs are properly escaped for unsafe
characters and that international domain names are properly encoded
to ASCII. See URI::Escape, URI::_punycode and Net::IDN::Encode.
* Redirection is very strict against the specification. Redirection is
only automatic for response codes 301, 302 and 307 if the request
method is 'GET' or 'HEAD'. Response code 303 is always converted
into a 'GET' redirection, as mandated by the specification. There is
no automatic support for status 305 ("Use proxy") redirections.
* Persistant connections are not supported. The "Connection" header
will always be set to "close".
* There is no provision for delaying a request body using an "Expect"
header. Unexpected "1XX" responses are silently ignored as per the
specification.
* Only 'chunked' "Transfer-Encoding" is supported.
* There is no support for a Request-URI of '*' for the 'OPTIONS'
request.
SEE ALSO
* LWP::UserAgent
AUTHORS
* Christian Hansen <chansen@cpan.org>
* David Golden <dagolden@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Christian Hansen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
name = HTTP-Tiny
author = Christian Hansen <chansen@cpan.org>
author = David Golden <dagolden@cpan.org>
license = Perl_5
copyright_holder = Christian Hansen
[@DAGOLDEN]
git_remote = github
#!/usr/bin/perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use HTTP::Tiny;
my $url = shift(@ARGV) || 'http://example.com';
my $response = HTTP::Tiny->new->get($url);
print "$response->{status} $response->{reason}\n";
while (my ($k, $v) = each %{$response->{headers}}) {
for (ref $v eq 'ARRAY' ? @$v : $v) {
print "$k: $_\n";
}
}
print $response->{content} if defined $response->{content};
#!/usr/bin/perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use HTTP::Tiny;
my $url = shift(@ARGV) || 'http://example.com';
my $file = shift(@ARGV) || 'example.output';
my $response = HTTP::Tiny->new->mirror($url, $file);
print "$response->{status} $response->{reason}\n";
while (my ($k, $v) = each %{$response->{headers}}) {
for (ref $v eq 'ARRAY' ? @$v : $v) {
print "$k: $_\n";
}
}
This diff is collapsed.
#!perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use Test::More;
use File::Find;
use File::Temp qw{ tempdir };
my @modules;
find(
sub {
return if $File::Find::name !~ /\.pm\z/;
my $found = $File::Find::name;
$found =~ s{^lib/}{};
$found =~ s{[/\\]}{::}g;
$found =~ s/\.pm$//;
# nothing to skip
push @modules, $found;
},
'lib',
);
my @scripts = glob "bin/*";
my $plan = scalar(@modules) + scalar(@scripts);
$plan ? (plan tests => $plan) : (plan skip_all => "no tests to run");
{
# fake home for cpan-testers
local $ENV{HOME} = tempdir( CLEANUP => 1 );
like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" )
for sort @modules;
SKIP: {
eval "use Test::Script 1.05; 1;";
skip "Test::Script needed to test script compilation", scalar(@scripts) if $@;
foreach my $file ( @scripts ) {
my $script = $file;
$script =~ s!.*/!!;
script_compiles( $file, "$script script compiles" );
}
}
}
#!perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use Test::More tests => 1;
BEGIN {
use_ok('HTTP::Tiny');
}
diag("HTTP::Tiny $HTTP::Tiny::VERSION, Perl $], $^X");
#!perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use Test::More tests => 2;
use HTTP::Tiny;
my @accessors = qw(agent default_headers max_redirect max_size proxy timeout);
my @methods = qw(new get request mirror);
my %api;
@api{@accessors} = (1) x @accessors;
@api{@methods} = (1) x @accessors;
can_ok('HTTP::Tiny', @methods, @accessors);
my @extra =
grep {! $api{$_} }
grep { $_ !~ /\A_/ }
grep {; no strict 'refs'; *{"HTTP::Tiny::$_"}{CODE} }
sort keys %HTTP::Tiny::;
ok( ! scalar @extra, "No unexpected subroutines defined" )
or diag "Found: @extra";
#!perl
#
# This file is part of HTTP-Tiny
#
# This software is copyright (c) 2011 by Christian Hansen.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
use Test::More;
use HTTP::Tiny;
my %usage = (
'get' => q/Usage: $http->get(URL, [HASHREF])/,
'mirror' => q/Usage: $http->mirror(URL, FILE, [HASHREF])/,
'request' => q/Usage: $http->request(METHOD, URL, [HASHREF])/,
);
my @cases = (