http3-server.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/3 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/http3.log";
  33. my $nghttpx = "nghttpx";
  34. my $listenport = 9017;
  35. my $connect = "127.0.0.1,8990";
  36. my $cert = "Server-localhost-sv";
  37. my $conf = "nghttpx.conf";
  38. my $dev_null = ($^O eq 'MSWin32' ? 'NUL' : '/dev/null');
  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 '--connect') {
  65. if($ARGV[1]) {
  66. $connect = $ARGV[1];
  67. $connect =~ s/:/,/;
  68. shift @ARGV;
  69. }
  70. }
  71. elsif($ARGV[0] eq '--cert') {
  72. if($ARGV[1]) {
  73. $cert = $ARGV[1];
  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: http3-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 --http2-proxy --backend=$connect ".
  106. "--backend-keep-alive-timeout=500ms ".
  107. "--frontend=\"*,$listenport\" ".
  108. "--frontend=\"*,$listenport;quic\" ".
  109. "--log-level=INFO ".
  110. "--pid-file=$pidfile ".
  111. "--errorlog-file=$logfile ".
  112. "--conf=$conf ".
  113. "$keyfile $certfile";
  114. print "RUN: $cmdline\n" if($verbose);
  115. exec("exec $cmdline 2>$dev_null");