Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created September 9, 2013 07:04
Show Gist options
  • Save aanoaa/6492308 to your computer and use it in GitHub Desktop.
Save aanoaa/6492308 to your computer and use it in GitHub Desktop.
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;
};
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";
@aanoaa
Copy link
Author

aanoaa commented Sep 9, 2013

#!/bin/sh
curl -X POST --trace trace.out --header "Transfer-Encoding: chunked" --header "Content-Type: application/octet-stream" -d @misc/data "http://localhost:5000/upload/10" > content.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment