http3-server.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 $pidfile = "log/nghttpx.pid";
  31. my $logfile = "log/http3.log";
  32. my $nghttpx = "nghttpx";
  33. my $listenport = 9015;
  34. my $connect = "127.0.0.1,8990";
  35. my $cert = "Server-localhost-sv";
  36. my $conf = "nghttpx.conf";
  37. #***************************************************************************
  38. # Process command line options
  39. #
  40. while(@ARGV) {
  41. if($ARGV[0] eq '--verbose') {
  42. $verbose = 1;
  43. }
  44. elsif($ARGV[0] eq '--pidfile') {
  45. if($ARGV[1]) {
  46. $pidfile = $ARGV[1];
  47. shift @ARGV;
  48. }
  49. }
  50. elsif($ARGV[0] eq '--nghttpx') {
  51. if($ARGV[1]) {
  52. $nghttpx = $ARGV[1];
  53. shift @ARGV;
  54. }
  55. }
  56. elsif($ARGV[0] eq '--port') {
  57. if($ARGV[1]) {
  58. $listenport = $ARGV[1];
  59. shift @ARGV;
  60. }
  61. }
  62. elsif($ARGV[0] eq '--connect') {
  63. if($ARGV[1]) {
  64. $connect = $ARGV[1];
  65. $connect =~ s/:/,/;
  66. shift @ARGV;
  67. }
  68. }
  69. elsif($ARGV[0] eq '--cert') {
  70. if($ARGV[1]) {
  71. $cert = $ARGV[1];
  72. shift @ARGV;
  73. }
  74. }
  75. elsif($ARGV[0] eq '--logfile') {
  76. if($ARGV[1]) {
  77. $logfile = $ARGV[1];
  78. shift @ARGV;
  79. }
  80. }
  81. elsif($ARGV[0] eq '--conf') {
  82. if($ARGV[1]) {
  83. $conf = $ARGV[1];
  84. shift @ARGV;
  85. }
  86. }
  87. else {
  88. print STDERR "\nWarning: http3-server.pl unknown parameter: $ARGV[0]\n";
  89. }
  90. shift @ARGV;
  91. }
  92. my $srcdir = dirname(__FILE__);
  93. $certfile = "$srcdir/certs/$cert.pem";
  94. $keyfile = "$srcdir/certs/$cert.key";
  95. $certfile = abs_path($certfile);
  96. $keyfile = abs_path($keyfile);
  97. my $cmdline="$nghttpx --http2-proxy --backend=$connect ".
  98. "--frontend=\"*,$listenport;quic\" ".
  99. "--log-level=INFO ".
  100. "--pid-file=$pidfile ".
  101. "--errorlog-file=$logfile ".
  102. "--conf=$conf ".
  103. "$keyfile $certfile";
  104. print "RUN: $cmdline\n" if($verbose);
  105. system("$cmdline 2>/dev/null");