about summary refs log tree commit homepage
path: root/t/httpd-corner.psgi
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-02-23 02:52:18 +0000
committerEric Wong <e@80x24.org>2016-02-23 03:44:20 +0000
commitdbaf64b646943bd92e1aa8d581e23a5adb4a3e57 (patch)
tree1281baf9597eab55dd8b5ed36508e7412a898d79 /t/httpd-corner.psgi
parente6085d1526b0948de16c145e11e511226126b7fa (diff)
downloadpublic-inbox-dbaf64b646943bd92e1aa8d581e23a5adb4a3e57.tar.gz
This is meant to provide an easy starting point for server admins.
It provides a basic HTTP server for admins unfamiliar with
configuring PSGI applications as well as being an identical
interface for management as our nntpd implementation.

This HTTP server may also be a generic Plack/PSGI server for
existing Plack/PSGI applications.
Diffstat (limited to 't/httpd-corner.psgi')
-rw-r--r--t/httpd-corner.psgi37
1 files changed, 37 insertions, 0 deletions
diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi
new file mode 100644
index 00000000..1947f376
--- /dev/null
+++ b/t/httpd-corner.psgi
@@ -0,0 +1,37 @@
+# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+# corner case tests for the generic PSGI server
+# Usage: plackup [OPTIONS] /path/to/this/file
+use strict;
+use warnings;
+use Plack::Request;
+use Plack::Builder;
+require Digest::SHA;
+my $app = sub {
+        my ($env) = @_;
+        my $path = $env->{PATH_INFO};
+        my $in = $env->{'psgi.input'};
+        my $actual = -s $in;
+        my $code = 500;
+        my $h = [ 'Content-Type' => 'text/plain' ];
+        my $body = [];
+        if ($path eq '/sha1') {
+                my $sha1 = Digest::SHA->new('SHA-1');
+                my $buf;
+                while (1) {
+                        my $r = $in->read($buf, 4096);
+                        die "read err: $!" unless defined $r;
+                        last if $r == 0;
+                        $sha1->add($buf);
+                }
+                $code = 200;
+                push @$body, $sha1->hexdigest;
+        }
+        [ $code, $h, $body ]
+};
+
+builder {
+        enable 'ContentLength';
+        enable 'Head';
+        $app;
+}