HTTP-Tiny
view release on metacpan or search on metacpan
[FIXED]
- Fixed bug receiving 0-length content bodies
0.030 2013-06-13 11:46:15 America/New_York
[FIXED]
- Requests with the empty string as body content no longer generate
'content-type' and 'content-length' headers.
0.029 2013-04-17 13:49:07 America/New_York
[FIXED]
- Checks for new enough OpenSSL library before using SNI (otherwise
IO::Socket::SSL throws warnings)
0.028 2013-03-05 14:11:57 America/New_York
The "success" field of the response will be true if the status code is
"2XX".
post_form
$response = $http->post_form($url, $form_data);
$response = $http->post_form($url, $form_data, \%options);
This method executes a "POST" request and sends the key/value pairs from
a form data hash or array reference to the given URL with a
"content-type" of "application/x-www-form-urlencoded". If data is
provided as an array reference, the order is preserved; if provided as a
hash reference, the terms are sorted by key for consistency. See
documentation for the "www_form_urlencode" method for details on the
encoding.
The URL must have unsafe characters escaped and international domain
names encoded. See request() for valid options and a description of the
response. Any "content-type" header or content in the options hashref
will be ignored.
The "success" field of the response will be true if the status code is
"2XX".
mirror
$response = $http->mirror($url, $file, \%options)
if ( $response->{success} ) {
print "$file is up to date\n";
}
The "Host" header is generated from the URL in accordance with RFC 2616.
It is a fatal error to specify "Host" in the "headers" option. Other
headers may be ignored or overwritten if necessary for transport
compliance.
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 "content" option is the empty string, no "content-type" or
"content-length" headers will be generated.
If the "data_callback" option is provided, it will be called iteratively
until the entire response body is received. The first argument will be a
string containing a chunk of the response body, the second argument will
be the in-progress response hash reference, as described below. (This
allows customizing the action of the callback based on the "status" or
"headers" received prior to the content body.)
Content data in the request/response is handled as "raw bytes". Any
mode => 'author',
);
my @params;
while( my @pair = each %form_data ) {
push @params, join("=", map { uri_escape_utf8($_) } @pair);
}
my $response = HTTP::Tiny->new->request('POST', $url, {
content => join("&", @params),
headers => { 'content-type' => 'application/x-www-form-urlencoded' }
});
print "$response->{status} $response->{reason}\n";
print $response->{content};
lib/HTTP/Tiny.pm view on Meta::CPAN
}
HERE
}
#pod =method post_form
#pod
#pod $response = $http->post_form($url, $form_data);
#pod $response = $http->post_form($url, $form_data, \%options);
#pod
#pod This method executes a C<POST> request and sends the key/value pairs from a
#pod form data hash or array reference to the given URL with a C<content-type> of
#pod C<application/x-www-form-urlencoded>. If data is provided as an array
#pod reference, the order is preserved; if provided as a hash reference, the terms
#pod are sorted by key for consistency. See documentation for the
#pod C<www_form_urlencode> method for details on the encoding.
#pod
#pod The URL must have unsafe characters escaped and international domain names
#pod encoded. See C<request()> for valid options and a description of the response.
#pod Any C<content-type> header or content in the options hashref will be ignored.
#pod
#pod The C<success> field of the response will be true if the status code is C<2XX>.
#pod
#pod =cut
sub post_form {
my ($self, $url, $data, $args) = @_;
(@_ == 3 || @_ == 4 && ref $args eq 'HASH')
or _croak(q/Usage: $http->post_form(URL, DATAREF, [HASHREF])/ . "\n");
lib/HTTP/Tiny.pm view on Meta::CPAN
$headers->{lc $key} = $value;
}
return $self->request('POST', $url, {
# Any existing 'headers' key in $args will be overridden with a
# normalized version below.
%$args,
content => $self->www_form_urlencode($data),
headers => {
%$headers,
'content-type' => 'application/x-www-form-urlencoded'
},
}
);
}
#pod =method mirror
#pod
#pod $response = $http->mirror($url, $file, \%options)
#pod if ( $response->{success} ) {
#pod print "$file is up to date\n";
lib/HTTP/Tiny.pm view on Meta::CPAN
#pod whose response will be taken as the address.
#pod
#pod The C<Host> header is generated from the URL in accordance with RFC 2616. It
#pod is a fatal error to specify C<Host> in the C<headers> option. Other headers
#pod may be ignored or overwritten if necessary for transport compliance.
#pod
#pod If the C<content> option is a code reference, it will be called iteratively
#pod to provide the content body of the request. It should return the empty
#pod string or undef when the iterator is exhausted.
#pod
#pod If the C<content> option is the empty string, no C<content-type> or
#pod C<content-length> headers will be generated.
#pod
#pod If the C<data_callback> option is provided, it will be called iteratively until
#pod the entire response body is received. The first argument will be a string
#pod containing a chunk of the response body, the second argument will be the
#pod in-progress response hash reference, as described below. (This allows
#pod customizing the action of the callback based on the C<status> or C<headers>
#pod received prior to the content body.)
#pod
#pod Content data in the request/response is handled as "raw bytes". Any
lib/HTTP/Tiny.pm view on Meta::CPAN
# otherwise, stringify it
$e = "$e";
$response = {
url => $url,
success => q{},
status => 599,
reason => 'Internal Exception',
content => $e,
headers => {
'content-type' => 'text/plain',
'content-length' => length $e,
},
( @{$args->{_redirects} || []} ? (redirects => delete $args->{_redirects}) : () ),
};
}
return $response;
}
#pod =method www_form_urlencode
#pod
lib/HTTP/Tiny.pm view on Meta::CPAN
$request->{headers}{'content-length'} = 0;
}
}
if ( defined $args->{content} ) {
if ( ref $args->{content} eq 'CODE' ) {
if ( exists $request->{'content-length'} && $request->{'content-length'} == 0 ) {
$request->{cb} = sub { "" };
}
else {
$request->{headers}{'content-type'} ||= "application/octet-stream";
$request->{headers}{'transfer-encoding'} = 'chunked'
unless exists $request->{headers}{'content-length'}
|| $request->{headers}{'transfer-encoding'};
$request->{cb} = $args->{content};
}
}
elsif ( length $args->{content} ) {
my $content = $args->{content};
if ( "$]" >= 5.008 ) {
utf8::downgrade($content, 1)
or die(qq/Wide character in request message body\n/);
}
$request->{headers}{'content-type'} ||= "application/octet-stream";
$request->{headers}{'content-length'} = length $content
unless $request->{headers}{'content-length'}
|| $request->{headers}{'transfer-encoding'};
$request->{cb} = sub { substr $content, 0, length $content, '' };
}
$request->{trailer_cb} = $args->{trailer_callback}
if ref $args->{trailer_callback} eq 'CODE';
}
### If we have a cookie jar, then maybe add relevant cookies
lib/HTTP/Tiny.pm view on Meta::CPAN
See C<request()> for valid options and a description of the response.
The C<success> field of the response will be true if the status code is C<2XX>.
=head2 post_form
$response = $http->post_form($url, $form_data);
$response = $http->post_form($url, $form_data, \%options);
This method executes a C<POST> request and sends the key/value pairs from a
form data hash or array reference to the given URL with a C<content-type> of
C<application/x-www-form-urlencoded>. If data is provided as an array
reference, the order is preserved; if provided as a hash reference, the terms
are sorted by key for consistency. See documentation for the
C<www_form_urlencode> method for details on the encoding.
The URL must have unsafe characters escaped and international domain names
encoded. See C<request()> for valid options and a description of the response.
Any C<content-type> header or content in the options hashref will be ignored.
The C<success> field of the response will be true if the status code is C<2XX>.
=head2 mirror
$response = $http->mirror($url, $file, \%options)
if ( $response->{success} ) {
print "$file is up to date\n";
}
lib/HTTP/Tiny.pm view on Meta::CPAN
=back
The C<Host> header is generated from the URL in accordance with RFC 2616. It
is a fatal error to specify C<Host> in the C<headers> option. Other headers
may be ignored or overwritten if necessary for transport compliance.
If the C<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 C<content> option is the empty string, no C<content-type> or
C<content-length> headers will be generated.
If the C<data_callback> option is provided, it will be called iteratively until
the entire response body is received. The first argument will be a string
containing a chunk of the response body, the second argument will be the
in-progress response hash reference, as described below. (This allows
customizing the action of the callback based on the C<status> or C<headers>
received prior to the content body.)
Content data in the request/response is handled as "raw bytes". Any
( run in 1.717 second using v1.01-cache-2.11-cpan-524268b4103 )