2
0

http2-server.pl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2016 - 2022, 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. 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. # Process command line options
  34. #
  35. while(@ARGV) {
  36. if($ARGV[0] eq '--verbose') {
  37. $verbose = 1;
  38. }
  39. elsif($ARGV[0] eq '--pidfile') {
  40. if($ARGV[1]) {
  41. $pidfile = $ARGV[1];
  42. shift @ARGV;
  43. }
  44. }
  45. elsif($ARGV[0] eq '--nghttpx') {
  46. if($ARGV[1]) {
  47. $nghttpx = $ARGV[1];
  48. shift @ARGV;
  49. }
  50. }
  51. elsif($ARGV[0] eq '--port') {
  52. if($ARGV[1]) {
  53. $listenport = $ARGV[1];
  54. shift @ARGV;
  55. }
  56. }
  57. elsif($ARGV[0] eq '--connect') {
  58. if($ARGV[1]) {
  59. $connect = $ARGV[1];
  60. $connect =~ s/:/,/;
  61. shift @ARGV;
  62. }
  63. }
  64. elsif($ARGV[0] eq '--logfile') {
  65. if($ARGV[1]) {
  66. $logfile = $ARGV[1];
  67. shift @ARGV;
  68. }
  69. }
  70. else {
  71. print STDERR "\nWarning: http2-server.pl unknown parameter: $ARGV[0]\n";
  72. }
  73. shift @ARGV;
  74. }
  75. my $cmdline="$nghttpx --backend=$connect ".
  76. "--frontend=\"*,$listenport;no-tls\" ".
  77. "--log-level=INFO ".
  78. "--pid-file=$pidfile ".
  79. "--errorlog-file=$logfile";
  80. print "RUN: $cmdline\n" if($verbose);
  81. system("$cmdline 2>/dev/null");