2
0

http2-server.pl 2.5 KB

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