Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http2-server.pl
2645 views
1
#!/usr/bin/env perl
2
#***************************************************************************
3
# _ _ ____ _
4
# Project ___| | | | _ \| |
5
# / __| | | | |_) | |
6
# | (__| |_| | _ <| |___
7
# \___|\___/|_| \_\_____|
8
#
9
# Copyright (C) Daniel Stenberg, <[email protected]>, 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
26
use strict;
27
use warnings;
28
29
# This script invokes nghttpx properly to have it serve HTTP/2 for us.
30
# nghttpx runs as a proxy in front of our "actual" HTTP/1 server.
31
use Cwd;
32
use Cwd 'abs_path';
33
use File::Basename;
34
use File::Spec;
35
36
my $verbose = 0; # set to 1 for debugging
37
my $logdir = "log";
38
my $pidfile = "$logdir/nghttpx.pid";
39
my $logfile = "$logdir/http2.log";
40
my $nghttpx = "nghttpx";
41
my $listenport = 9015;
42
my $listenport2 = 9016;
43
my $connect = "127.0.0.1,8990";
44
my $conf = "nghttpx.conf";
45
my $cert = "test-localhost";
46
my $dev_null = File::Spec->devnull();
47
48
#***************************************************************************
49
# Process command line options
50
#
51
while(@ARGV) {
52
if($ARGV[0] eq '--verbose') {
53
$verbose = 1;
54
}
55
elsif($ARGV[0] eq '--pidfile') {
56
if($ARGV[1]) {
57
$pidfile = $ARGV[1];
58
shift @ARGV;
59
}
60
}
61
elsif($ARGV[0] eq '--nghttpx') {
62
if($ARGV[1]) {
63
$nghttpx = $ARGV[1];
64
shift @ARGV;
65
}
66
}
67
elsif($ARGV[0] eq '--port') {
68
if($ARGV[1]) {
69
$listenport = $ARGV[1];
70
shift @ARGV;
71
}
72
}
73
elsif($ARGV[0] eq '--port2') {
74
if($ARGV[1]) {
75
$listenport2 = $ARGV[1];
76
shift @ARGV;
77
}
78
}
79
elsif($ARGV[0] eq '--connect') {
80
if($ARGV[1]) {
81
$connect = $ARGV[1];
82
$connect =~ s/:/,/;
83
shift @ARGV;
84
}
85
}
86
elsif($ARGV[0] eq '--logfile') {
87
if($ARGV[1]) {
88
$logfile = $ARGV[1];
89
shift @ARGV;
90
}
91
}
92
elsif($ARGV[0] eq '--logdir') {
93
if($ARGV[1]) {
94
$logdir = $ARGV[1];
95
shift @ARGV;
96
}
97
}
98
elsif($ARGV[0] eq '--conf') {
99
if($ARGV[1]) {
100
$conf = $ARGV[1];
101
shift @ARGV;
102
}
103
}
104
elsif($ARGV[0]) {
105
print STDERR "\nWarning: http2-server.pl unknown parameter: $ARGV[0]\n";
106
}
107
shift @ARGV;
108
}
109
110
my $certfile = abs_path("certs/$cert.pem");
111
my $keyfile = abs_path("certs/$cert.key");
112
113
my $cmdline="$nghttpx --backend=$connect ".
114
"--backend-keep-alive-timeout=500ms ".
115
"--frontend=\"*,$listenport;no-tls\" ".
116
"--frontend=\"*,$listenport2\" ".
117
"--log-level=INFO ".
118
"--pid-file=$pidfile ".
119
"--conf=$conf ".
120
"--errorlog-file=$logfile ".
121
"$keyfile $certfile";
122
print "RUN: $cmdline\n" if($verbose);
123
exec("exec $cmdline 2>$dev_null");
124
125