Created
September 9, 2013 07:04
-
-
Save aanoaa/6492308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Plack::Request; | |
use File::Slurp qw/write_file slurp/; | |
my $app = sub { | |
my $req = Plack::Request->new(shift); | |
my $input = $req->body; # `psgi.input` handle | |
my $len = 1024 * 8; | |
my $offset = 0; | |
my $buf; | |
my $content = ''; | |
while (my $read = $input->read($buf, $len)) { | |
print "read [$read] bytes\n"; | |
} | |
my $res = $req->new_response(200); | |
$res->content_type('text/plain'); | |
$res->content(slurp 'misc/data'); | |
return $res->finalize; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use HTTP::Tiny; | |
use File::Slurp qw/slurp/; | |
my $http = HTTP::Tiny->new; | |
my $offset = 0; | |
my $body = slurp 'misc/data'; | |
my $length = length $body; | |
my $chunk_lenth = 1024 * 8; | |
my $res = $http->request( | |
'POST', | |
'http://localhost:5000/', | |
{ | |
content => sub { | |
return '' unless $offset < $length; | |
my $chunk = substr $body, $offset, $chunk_lenth; | |
$offset += $chunk_lenth; | |
return $chunk; | |
} | |
} | |
); | |
print "$res->{status}: $res->{reason}\n"; |
Author
aanoaa
commented
Sep 9, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment