quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

http3-server.pl (3377B)


      1 #!/usr/bin/env perl
      2 #***************************************************************************
      3 #                                  _   _ ____  _
      4 #  Project                     ___| | | |  _ \| |
      5 #                             / __| | | | |_) | |
      6 #                            | (__| |_| |  _ <| |___
      7 #                             \___|\___/|_| \_\_____|
      8 #
      9 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
     10 #
     11 # This software is licensed as described in the file COPYING, which
     12 # you should have received as part of this distribution. The terms
     13 # are also available at https://curl.se/docs/copyright.html.
     14 #
     15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
     16 # copies of the Software, and permit persons to whom the Software is
     17 # furnished to do so, under the terms of the COPYING file.
     18 #
     19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     20 # KIND, either express or implied.
     21 #
     22 # SPDX-License-Identifier: curl
     23 #
     24 #***************************************************************************
     25 
     26 # This script invokes nghttpx properly to have it serve HTTP/3 for us.
     27 # nghttpx runs as a proxy in front of our "actual" HTTP/1 server.
     28 
     29 use Cwd;
     30 use Cwd 'abs_path';
     31 use File::Basename;
     32 use File::Spec;
     33 
     34 my $logdir = "log";
     35 my $pidfile = "$logdir/nghttpx.pid";
     36 my $logfile = "$logdir/http3.log";
     37 my $nghttpx = "nghttpx";
     38 my $listenport = 9017;
     39 my $connect = "127.0.0.1,8990";
     40 my $cert = "test-localhost";
     41 my $conf = "nghttpx.conf";
     42 my $dev_null = File::Spec->devnull();
     43 
     44 #***************************************************************************
     45 # Process command line options
     46 #
     47 while(@ARGV) {
     48     if($ARGV[0] eq '--verbose') {
     49         $verbose = 1;
     50     }
     51     elsif($ARGV[0] eq '--pidfile') {
     52         if($ARGV[1]) {
     53             $pidfile = $ARGV[1];
     54             shift @ARGV;
     55         }
     56     }
     57     elsif($ARGV[0] eq '--nghttpx') {
     58         if($ARGV[1]) {
     59             $nghttpx = $ARGV[1];
     60             shift @ARGV;
     61         }
     62     }
     63     elsif($ARGV[0] eq '--port') {
     64         if($ARGV[1]) {
     65             $listenport = $ARGV[1];
     66             shift @ARGV;
     67         }
     68     }
     69     elsif($ARGV[0] eq '--connect') {
     70         if($ARGV[1]) {
     71             $connect = $ARGV[1];
     72             $connect =~ s/:/,/;
     73             shift @ARGV;
     74         }
     75     }
     76     elsif($ARGV[0] eq '--cert') {
     77         if($ARGV[1]) {
     78             $cert = $ARGV[1];
     79             shift @ARGV;
     80         }
     81     }
     82     elsif($ARGV[0] eq '--logfile') {
     83         if($ARGV[1]) {
     84             $logfile = $ARGV[1];
     85             shift @ARGV;
     86         }
     87     }
     88     elsif($ARGV[0] eq '--logdir') {
     89         if($ARGV[1]) {
     90             $logdir = $ARGV[1];
     91             shift @ARGV;
     92         }
     93     }
     94     elsif($ARGV[0] eq '--conf') {
     95         if($ARGV[1]) {
     96             $conf = $ARGV[1];
     97             shift @ARGV;
     98         }
     99     }
    100     else {
    101         print STDERR "\nWarning: http3-server.pl unknown parameter: $ARGV[0]\n";
    102     }
    103     shift @ARGV;
    104 }
    105 
    106 $certfile = abs_path("certs/$cert.pem");
    107 $keyfile = abs_path("certs/$cert.key");
    108 
    109 my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
    110     "--backend-keep-alive-timeout=500ms ".
    111     "--frontend=\"*,$listenport\" ".
    112     "--frontend=\"*,$listenport;quic\" ".
    113     "--log-level=INFO ".
    114     "--pid-file=$pidfile ".
    115     "--errorlog-file=$logfile ".
    116     "--conf=$conf ".
    117     "$keyfile $certfile";
    118 print "RUN: $cmdline\n" if($verbose);
    119 exec("exec $cmdline 2>$dev_null");