http3-server.pl 3.3 KB

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