http2-server.pl 3.3 KB

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