http2-server.pl (3408B)
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. 28 use Cwd; 29 use Cwd 'abs_path'; 30 use File::Basename; 31 use File::Spec; 32 33 my $logdir = "log"; 34 my $pidfile = "$logdir/nghttpx.pid"; 35 my $logfile = "$logdir/http2.log"; 36 my $nghttpx = "nghttpx"; 37 my $listenport = 9015; 38 my $listenport2 = 9016; 39 my $connect = "127.0.0.1,8990"; 40 my $conf = "nghttpx.conf"; 41 my $cert = "test-localhost"; 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 '--port2') { 70 if($ARGV[1]) { 71 $listenport2 = $ARGV[1]; 72 shift @ARGV; 73 } 74 } 75 elsif($ARGV[0] eq '--connect') { 76 if($ARGV[1]) { 77 $connect = $ARGV[1]; 78 $connect =~ s/:/,/; 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 elsif($ARGV[0]) { 101 print STDERR "\nWarning: http2-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 --backend=$connect ". 110 "--backend-keep-alive-timeout=500ms ". 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"; 118 print "RUN: $cmdline\n" if($verbose); 119 exec("exec $cmdline 2>$dev_null");