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