Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http-server.pl
2065 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
BEGIN {
30
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
31
push(@INC, ".");
32
}
33
34
use File::Basename;
35
36
use serverhelp qw(
37
server_pidfilename
38
server_logfilename
39
server_exe
40
);
41
42
my $verbose = 0; # set to 1 for debugging
43
my $port = 8990; # just a default
44
my $unix_socket; # location to place a listening Unix socket
45
my $ipvnum = 4; # default IP version of http server
46
my $idnum = 1; # default http server instance number
47
my $proto = 'http'; # protocol the http server speaks
48
my $pidfile; # pid file
49
my $portfile; # port number file
50
my $logfile; # log file
51
my $cmdfile; # command file
52
my $connect; # IP to connect to on CONNECT
53
my $keepalive_secs; # number of seconds to keep idle connections
54
my $srcdir;
55
my $gopher = 0;
56
57
my $flags = "";
58
my $path = '.';
59
my $logdir = $path .'/log';
60
my $piddir;
61
62
while(@ARGV) {
63
if($ARGV[0] eq '--pidfile') {
64
if($ARGV[1]) {
65
$pidfile = $ARGV[1];
66
shift @ARGV;
67
}
68
}
69
elsif($ARGV[0] eq '--portfile') {
70
if($ARGV[1]) {
71
$portfile = $ARGV[1];
72
shift @ARGV;
73
}
74
}
75
elsif($ARGV[0] eq '--config') {
76
if($ARGV[1]) {
77
$cmdfile = $ARGV[1];
78
shift @ARGV;
79
}
80
}
81
elsif($ARGV[0] eq '--logfile') {
82
if($ARGV[1]) {
83
$logfile = $ARGV[1];
84
shift @ARGV;
85
}
86
}
87
elsif($ARGV[0] eq '--logdir') {
88
if($ARGV[1]) {
89
$logdir = $ARGV[1];
90
shift @ARGV;
91
}
92
}
93
elsif($ARGV[0] eq '--srcdir') {
94
if($ARGV[1]) {
95
$srcdir = $ARGV[1];
96
shift @ARGV;
97
}
98
}
99
elsif($ARGV[0] eq '--ipv4') {
100
$ipvnum = 4;
101
}
102
elsif($ARGV[0] eq '--ipv6') {
103
$ipvnum = 6;
104
}
105
elsif($ARGV[0] eq '--unix-socket') {
106
$ipvnum = 'unix';
107
if($ARGV[1]) {
108
$unix_socket = $ARGV[1];
109
shift @ARGV;
110
}
111
}
112
elsif($ARGV[0] eq '--gopher') {
113
$gopher = 1;
114
}
115
elsif($ARGV[0] eq '--port') {
116
if($ARGV[1] =~ /^(\d+)$/) {
117
$port = $1;
118
shift @ARGV;
119
}
120
}
121
elsif($ARGV[0] eq '--connect') {
122
if($ARGV[1]) {
123
$connect = $ARGV[1];
124
shift @ARGV;
125
}
126
}
127
elsif($ARGV[0] eq '--keepalive') {
128
if($ARGV[1]) {
129
$keepalive_secs = $ARGV[1];
130
shift @ARGV;
131
}
132
}
133
elsif($ARGV[0] eq '--id') {
134
if($ARGV[1] =~ /^(\d+)$/) {
135
$idnum = $1 if($1 > 0);
136
shift @ARGV;
137
}
138
}
139
elsif($ARGV[0] eq '--verbose') {
140
$verbose = 1;
141
}
142
else {
143
print STDERR "\nWarning: http-server.pl unknown parameter: $ARGV[0]\n";
144
}
145
shift @ARGV;
146
}
147
148
#***************************************************************************
149
# Initialize command line option dependent variables
150
#
151
152
if($pidfile) {
153
# Use our pidfile directory to store the other pidfiles
154
$piddir = dirname($pidfile);
155
}
156
else {
157
# Use the current directory to store all the pidfiles
158
$piddir = $path;
159
$pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
160
}
161
if(!$portfile) {
162
$portfile = server_portfilename($piddir, $proto, $ipvnum, $idnum);
163
}
164
if(!$srcdir) {
165
$srcdir = $ENV{'srcdir'} || '.';
166
}
167
if(!$logfile) {
168
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
169
}
170
171
$flags .= "--pidfile \"$pidfile\" ".
172
"--cmdfile \"$cmdfile\" ".
173
"--logfile \"$logfile\" ".
174
"--logdir \"$logdir\" ".
175
"--portfile \"$portfile\" ";
176
$flags .= "--gopher " if($gopher);
177
$flags .= "--connect $connect " if($connect);
178
$flags .= "--keepalive $keepalive_secs " if($keepalive_secs);
179
if($ipvnum eq 'unix') {
180
$flags .= "--unix-socket '$unix_socket' ";
181
} else {
182
$flags .= "--ipv$ipvnum --port $port ";
183
}
184
$flags .= "--srcdir \"$srcdir\"";
185
186
if($verbose) {
187
print STDERR "RUN: ".server_exe('sws')." $flags\n";
188
}
189
190
$| = 1;
191
exec("exec ".server_exe('sws')." $flags");
192
193