| 1 |
#!/usr/bin/env perl |
| 2 |
#*************************************************************************** |
| 3 |
# _ _ ____ _ |
| 4 |
# Project ___| | | | _ \| | |
| 5 |
# / __| | | | |_) | | |
| 6 |
# | (__| |_| | _ <| |___ |
| 7 |
# \___|\___/|_| \_\_____| |
| 8 |
# |
| 9 |
# Copyright (C) 2016, Daniel Stenberg, <[email protected]>, 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.haxx.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 |
#*************************************************************************** |
| 23 |
|
| 24 |
# This script invokes nghttpx properly to have it serve HTTP/2 for us. |
| 25 |
# nghttpx runs as a proxy in front of our "actual" HTTP/1 server. |
| 26 |
|
| 27 |
my $pidfile = "log/nghttpx.pid"; |
| 28 |
my $logfile = "log/http2.log"; |
| 29 |
my $nghttpx = "nghttpx"; |
| 30 |
my $listenport = 9015; |
| 31 |
my $connect = "127.0.0.1,8990"; |
| 32 |
|
| 33 |
#*************************************************************************** |
| 34 |
# Process command line options |
| 35 |
# |
| 36 |
while(@ARGV) { |
| 37 |
if($ARGV[0] eq '--verbose') { |
| 38 |
$verbose = 1; |
| 39 |
} |
| 40 |
elsif($ARGV[0] eq '--pidfile') { |
| 41 |
if($ARGV[1]) { |
| 42 |
$pidfile = $ARGV[1]; |
| 43 |
shift @ARGV; |
| 44 |
} |
| 45 |
} |
| 46 |
elsif($ARGV[0] eq '--nghttpx') { |
| 47 |
if($ARGV[1]) { |
| 48 |
$nghttpx = $ARGV[1]; |
| 49 |
shift @ARGV; |
| 50 |
} |
| 51 |
} |
| 52 |
elsif($ARGV[0] eq '--port') { |
| 53 |
if($ARGV[1]) { |
| 54 |
$listenport = $ARGV[1]; |
| 55 |
shift @ARGV; |
| 56 |
} |
| 57 |
} |
| 58 |
elsif($ARGV[0] eq '--connect') { |
| 59 |
if($ARGV[1]) { |
| 60 |
$connect = $ARGV[1]; |
| 61 |
$connect =~ s/:/,/; |
| 62 |
shift @ARGV; |
| 63 |
} |
| 64 |
} |
| 65 |
elsif($ARGV[0] eq '--logfile') { |
| 66 |
if($ARGV[1]) { |
| 67 |
$logfile = $ARGV[1]; |
| 68 |
shift @ARGV; |
| 69 |
} |
| 70 |
} |
| 71 |
else { |
| 72 |
print STDERR "\nWarning: http2-server.pl unknown parameter: $ARGV[0]\n"; |
| 73 |
} |
| 74 |
shift @ARGV; |
| 75 |
} |
| 76 |
|
| 77 |
my $cmdline="$nghttpx --backend=$connect ". |
| 78 |
"--frontend=\"*,$listenport;no-tls\" ". |
| 79 |
"--log-level=INFO ". |
| 80 |
"--pid-file=$pidfile ". |
| 81 |
"--errorlog-file=$logfile"; |
| 82 |
print "RUN: $cmdline\n" if($verbose); |
| 83 |
system("$cmdline 2>/dev/null"); |