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/2 for us. 27# nghttpx runs as a proxy in front of our "actual" HTTP/1 server. 28use Cwd; 29use Cwd 'abs_path'; 30use File::Basename; 31 32my $logdir = "log"; 33my $pidfile = "$logdir/nghttpx.pid"; 34my $logfile = "$logdir/http2.log"; 35my $nghttpx = "nghttpx"; 36my $listenport = 9015; 37my $listenport2 = 9016; 38my $connect = "127.0.0.1,8990"; 39my $conf = "nghttpx.conf"; 40my $cert = "Server-localhost-sv"; 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 '--port2') { 68 if($ARGV[1]) { 69 $listenport2 = $ARGV[1]; 70 shift @ARGV; 71 } 72 } 73 elsif($ARGV[0] eq '--connect') { 74 if($ARGV[1]) { 75 $connect = $ARGV[1]; 76 $connect =~ s/:/,/; 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: http2-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 --backend=$connect ". 111 "--frontend=\"*,$listenport;no-tls\" ". 112 "--frontend=\"*,$listenport2\" ". 113 "--log-level=INFO ". 114 "--pid-file=$pidfile ". 115 "--conf=$conf ". 116 "--errorlog-file=$logfile ". 117 "$keyfile $certfile"; 118print "RUN: $cmdline\n" if($verbose); 119system("$cmdline 2>/dev/null"); 120