Perl x Open Food Facts Hackathon: Paris, France - May 24-25 Learn more

NAME

HTTP::Tiny::Bandwidth - HTTP::Tiny with limitation of download/upload speed

SYNOPSIS

my $http = HTTP::Tiny::Bandwidth->new;
# limit download speed
download_limit_bps => 5 * (1024**2), # limit 5Mbps
});
# you can save memory with mirror method
my $res = $http->mirror(
"/path/to/save/perl-5.22.0.tar.gz",
{ download_limit_bps => 5 * (1024**2) }, # limit 5Mbps
);
# limit upload speed
my $res = $http->post("http://example.com", {
content_file => "big-file.txt", # or content_fh
upload_limit_bps => 5 * (1024**2), # limit 5Mbps
});

DESCRIPTION

HTTP::Tiny::Bandwidth is a subclass of HTTP::Tiny which can limit download/upload speed.

If you want to use LWP::UserAgent with limitation of download/upload speed, see eg directory.

HOW TO LIMIT DOWNLOAD SPEED

HTTP::Tiny::Bandwidth's request/get/... and mirror methods accepts download_limit_bps option:

my $http = HTTP::Tiny::Bandwidth->new;
download_limit_bps => 5 * (1024**2),
});
my $res = $http->mirror(
"/path/to/save/perl-5.22.0.tar.gz",
{ download_limit_bps => 5 * (1024**2) },
);

HOW TO LIMIT UPLOAD SPEED

HTTP::Tiny::Bandwidth's request/post/put/... methods accepts content_file, content_fh, upload_limit_bps options:

my $http = HTTP::Tiny::Bandwidth->new;
# content_file
my $res = $http->post("http://example.com", {
content_file => "big-file.txt",
upload_limit_bps => 5 * (1024**2), # limit 5Mbps
});
# or, you can specify content_fh
open my $fh, "<", "big-file.txt" or die;
my $res = $http->post("http://example.com", {
content_fh => $fh,
upload_limit_bps => 5 * (1024**2), # limit 5Mbps
});

SEE ALSO

HTTP::Tiny

COPYRIGHT AND LICENSE

Copyright 2015 Shoichi Kaji

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.