]> Sergey Matveev's repositories - public-inbox.git/blob - t/httpd-corner.psgi
initial public-inbox-httpd implemenation
[public-inbox.git] / t / httpd-corner.psgi
1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 # corner case tests for the generic PSGI server
4 # Usage: plackup [OPTIONS] /path/to/this/file
5 use strict;
6 use warnings;
7 use Plack::Request;
8 use Plack::Builder;
9 require Digest::SHA;
10 my $app = sub {
11         my ($env) = @_;
12         my $path = $env->{PATH_INFO};
13         my $in = $env->{'psgi.input'};
14         my $actual = -s $in;
15         my $code = 500;
16         my $h = [ 'Content-Type' => 'text/plain' ];
17         my $body = [];
18         if ($path eq '/sha1') {
19                 my $sha1 = Digest::SHA->new('SHA-1');
20                 my $buf;
21                 while (1) {
22                         my $r = $in->read($buf, 4096);
23                         die "read err: $!" unless defined $r;
24                         last if $r == 0;
25                         $sha1->add($buf);
26                 }
27                 $code = 200;
28                 push @$body, $sha1->hexdigest;
29         }
30         [ $code, $h, $body ]
31 };
32
33 builder {
34         enable 'ContentLength';
35         enable 'Head';
36         $app;
37 }