use Cwd;
use Cwd 'abs_path';
use File::Basename;
use File::Spec;
my $logdir = "log";
my $pidfile = "$logdir/nghttpx.pid";
my $logfile = "$logdir/http3.log";
my $nghttpx = "nghttpx";
my $listenport = 9017;
my $connect = "127.0.0.1,8990";
my $cert = "test-localhost";
my $conf = "nghttpx.conf";
my $dev_null = File::Spec->devnull();
while(@ARGV) {
if($ARGV[0] eq '--verbose') {
$verbose = 1;
}
elsif($ARGV[0] eq '--pidfile') {
if($ARGV[1]) {
$pidfile = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--nghttpx') {
if($ARGV[1]) {
$nghttpx = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--port') {
if($ARGV[1]) {
$listenport = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--connect') {
if($ARGV[1]) {
$connect = $ARGV[1];
$connect =~ s/:/,/;
shift @ARGV;
}
}
elsif($ARGV[0] eq '--cert') {
if($ARGV[1]) {
$cert = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--logfile') {
if($ARGV[1]) {
$logfile = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--logdir') {
if($ARGV[1]) {
$logdir = $ARGV[1];
shift @ARGV;
}
}
elsif($ARGV[0] eq '--conf') {
if($ARGV[1]) {
$conf = $ARGV[1];
shift @ARGV;
}
}
else {
print STDERR "\nWarning: http3-server.pl unknown parameter: $ARGV[0]\n";
}
shift @ARGV;
}
$certfile = abs_path("certs/$cert.pem");
$keyfile = abs_path("certs/$cert.key");
my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
"--backend-keep-alive-timeout=500ms ".
"--frontend=\"*,$listenport\" ".
"--frontend=\"*,$listenport;quic\" ".
"--log-level=INFO ".
"--pid-file=$pidfile ".
"--errorlog-file=$logfile ".
"--conf=$conf ".
"$keyfile $certfile";
print "RUN: $cmdline\n" if($verbose);
exec("exec $cmdline 2>$dev_null");