You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

99 lines
2.1 KiB

#!/usr/bin/env perl
# Pastry - paste service
#
# Written in 2020 by Lucas
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication
# along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
use v5.12;
use strict;
use warnings;
use IO::Handle;
use File::Temp qw(tempfile);
use Scalar::Util qw(openhandle);
use FCGI;
use FCGI::ProcManager;
my $UPLOAD_DIR = "./u";
my $DOMAIN = "example.com";
sub err_400 (*@)
{
my ($outh, @msg) = @_;
print $outh "Content-Type: text/plain\n";
print $outh "Status: 400 Bad Request\n";
print $outh "\n";
print $outh (@msg ? @msg : "Bad Request"), "\n";
}
sub err_405 (*)
{
my $outh = shift;
print $outh "Content-Type: text/plain\n";
print $outh "Status: 405 Method Not Allowed\n";
print $outh "\n";
print $outh "Only GET and POST are supported\n";
}
sub err_500 (*@)
{
my ($outh, @msg) = @_;
print $outh "Content-Type: text/plain\n";
print $outh "Status: 500 Internal Server Error\n";
print $outh "\n";
print $outh (@msg ? @msg : "Internal Server Error"), "\n";
}
sub handle_request ($$)
{
my ($req, $cgi) = @_;
my %env = %{$req->GetEnvironment()};
my ($inh, $outh, $errh) = $req->GetHandles();
if (($env{"REQUEST_METHOD"} || "") !~ m/^(get|post)$/i) {
err_405 $outh;
return;
}
print $outh "Content-Type: text/plain\n";
print $outh "\n";
print $outh "Hellow world\n";
}
sub main ()
{
my $sock = FCGI::OpenSocket(":9090", 5);
my $pm = FCGI::ProcManager->new({
n_processes => 2,
pm_title => "pastry-fcgi-pm",
});
$pm->pm_manage();
my %env;
my $req = FCGI::Request(IO::Handle->new(), IO::Handle->new(),
IO::Handle->new(), \%env, $sock, FCGI::FAIL_ACCEPT_ON_INTR);
my $cgi = undef;
while ($req->Accept() >= 0) {
$pm->pm_pre_dispatch();
handle_request($req, $cgi);
$req->Finish();
$pm->pm_post_dispatch();
}
FCGI::CloseSocket($sock);
}
main();