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"; 41my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null'); 42 43#*************************************************************************** 44# Process command line options 45# 46while(@ARGV) { 47 if($ARGV[0] eq '--verbose') { 48 $verbose = 1; 49 } 50 elsif($ARGV[0] eq '--pidfile') { 51 if($ARGV[1]) { 52 $pidfile = $ARGV[1]; 53 shift @ARGV; 54 } 55 } 56 elsif($ARGV[0] eq '--nghttpx') { 57 if($ARGV[1]) { 58 $nghttpx = $ARGV[1]; 59 shift @ARGV; 60 } 61 } 62 elsif($ARGV[0] eq '--port') { 63 if($ARGV[1]) { 64 $listenport = $ARGV[1]; 65 shift @ARGV; 66 } 67 } 68 elsif($ARGV[0] eq '--port2') { 69 if($ARGV[1]) { 70 $listenport2 = $ARGV[1]; 71 shift @ARGV; 72 } 73 } 74 elsif($ARGV[0] eq '--connect') { 75 if($ARGV[1]) { 76 $connect = $ARGV[1]; 77 $connect =~ s/:/,/; 78 shift @ARGV; 79 } 80 } 81 elsif($ARGV[0] eq '--logfile') { 82 if($ARGV[1]) { 83 $logfile = $ARGV[1]; 84 shift @ARGV; 85 } 86 } 87 elsif($ARGV[0] eq '--logdir') { 88 if($ARGV[1]) { 89 $logdir = $ARGV[1]; 90 shift @ARGV; 91 } 92 } 93 elsif($ARGV[0] eq '--conf') { 94 if($ARGV[1]) { 95 $conf = $ARGV[1]; 96 shift @ARGV; 97 } 98 } 99 else { 100 print STDERR "\nWarning: http2-server.pl unknown parameter: $ARGV[0]\n"; 101 } 102 shift @ARGV; 103} 104 105my $srcdir = dirname(__FILE__); 106$certfile = "$srcdir/certs/$cert.pem"; 107$keyfile = "$srcdir/certs/$cert.key"; 108$certfile = abs_path($certfile); 109$keyfile = abs_path($keyfile); 110 111my $cmdline="$nghttpx --backend=$connect ". 112 "--backend-keep-alive-timeout=500ms ". 113 "--frontend=\"*,$listenport;no-tls\" ". 114 "--frontend=\"*,$listenport2\" ". 115 "--log-level=INFO ". 116 "--pid-file=$pidfile ". 117 "--conf=$conf ". 118 "--errorlog-file=$logfile ". 119 "$keyfile $certfile"; 120print "RUN: $cmdline\n" if($verbose); 121exec("exec $cmdline 2>$dev_null"); 122