• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
29use Cwd;
30use Cwd 'abs_path';
31use File::Basename;
32
33my $logdir = "log";
34my $pidfile = "$logdir/nghttpx.pid";
35my $logfile = "$logdir/http3.log";
36my $nghttpx = "nghttpx";
37my $listenport = 9017;
38my $connect = "127.0.0.1,8990";
39my $cert = "Server-localhost-sv";
40my $conf = "nghttpx.conf";
41
42#***************************************************************************
43# Process command line options
44#
45while(@ARGV) {
46    if($ARGV[0] eq '--verbose') {
47        $verbose = 1;
48    }
49    elsif($ARGV[0] eq '--pidfile') {
50        if($ARGV[1]) {
51            $pidfile = $ARGV[1];
52            shift @ARGV;
53        }
54    }
55    elsif($ARGV[0] eq '--nghttpx') {
56        if($ARGV[1]) {
57            $nghttpx = $ARGV[1];
58            shift @ARGV;
59        }
60    }
61    elsif($ARGV[0] eq '--port') {
62        if($ARGV[1]) {
63            $listenport = $ARGV[1];
64            shift @ARGV;
65        }
66    }
67    elsif($ARGV[0] eq '--connect') {
68        if($ARGV[1]) {
69            $connect = $ARGV[1];
70            $connect =~ s/:/,/;
71            shift @ARGV;
72        }
73    }
74    elsif($ARGV[0] eq '--cert') {
75        if($ARGV[1]) {
76            $cert = $ARGV[1];
77            shift @ARGV;
78        }
79    }
80    elsif($ARGV[0] eq '--logfile') {
81        if($ARGV[1]) {
82            $logfile = $ARGV[1];
83            shift @ARGV;
84        }
85    }
86    elsif($ARGV[0] eq '--logdir') {
87        if($ARGV[1]) {
88            $logdir = $ARGV[1];
89            shift @ARGV;
90        }
91    }
92    elsif($ARGV[0] eq '--conf') {
93        if($ARGV[1]) {
94            $conf = $ARGV[1];
95            shift @ARGV;
96        }
97    }
98    else {
99        print STDERR "\nWarning: http3-server.pl unknown parameter: $ARGV[0]\n";
100    }
101    shift @ARGV;
102}
103
104my $srcdir = dirname(__FILE__);
105$certfile = "$srcdir/certs/$cert.pem";
106$keyfile = "$srcdir/certs/$cert.key";
107$certfile = abs_path($certfile);
108$keyfile = abs_path($keyfile);
109
110my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
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";
118print "RUN: $cmdline\n" if($verbose);
119system("$cmdline 2>/dev/null");
120