master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23#***************************************************************************
25# This perl module contains functions useful in writing test servers.
27package serverhelp;
29use strict;
30use warnings;
32use Time::HiRes;
34BEGIN {
35 use base qw(Exporter);
37 our @EXPORT_OK = qw(
38 logmsg
39 $logfile
40 serverfactors
41 servername_id
42 servername_str
43 servername_canon
44 server_pidfilename
45 server_portfilename
46 server_logfilename
47 server_cmdfilename
48 server_inputfilename
49 server_outputfilename
50 server_exe
51 server_exe_args
52 mainsockf_pidfilename
53 mainsockf_logfilename
54 datasockf_pidfilename
55 datasockf_logfilename
56 );
57}
59use globalconfig;
60use pathhelp qw(
61 exe_ext
62 );
63use testutil qw(
64 exerunner
65 );
67our $logfile; # server log filename, for logmsg
69#***************************************************************************
70# For convenience, test harness uses 'https' literal as values for 'proto'
71# variable in order to differentiate different servers. 'https' literal is
72# used for stunnel based https test servers.
74#**********************************************************************
75# logmsg is general message logging subroutine for our test servers.
76#
77sub logmsg {
78 my ($seconds, $usec) = Time::HiRes::gettimeofday();
79 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($seconds);
80 my $now = sprintf("%02d:%02d:%02d.%06d ", $hour, $min, $sec, $usec);
81 # we see warnings on Windows run that $logfile is used uninitialized
82 # TODO: not found yet where this comes from
83 $logfile = "serverhelp_uninitialized.log" if(!$logfile);
84 if(open(my $logfilefh, ">>", $logfile)) {
85 print $logfilefh $now;
86 print $logfilefh @_;
87 close($logfilefh);
88 }
89}
91#***************************************************************************
92# Return server characterization factors given a server id string.
93#
94sub serverfactors {
95 my $server = $_[0];
96 my $proto;
97 my $ipvnum;
98 my $idnum;
100 if($server =~
101 /^((ftp|http|imap|pop3|smtp)s?)(\d*)(-ipv6|)$/) {
102 $proto = $1;
103 $idnum = ($3 && ($3 > 1)) ? $3 : 1;
104 $ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4;
105 }
106 elsif($server =~
107 /^(dns|tftp|sftp|socks|ssh|rtsp|gopher)(\d*)(-ipv6|)$/) {
108 $proto = $1;
109 $idnum = ($2 && ($2 > 1)) ? $2 : 1;
110 $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
111 }
112 else {
113 die "invalid server id: '$server'"
114 }
115 return($proto, $ipvnum, $idnum);
116}
118#***************************************************************************
119# Return server name string formatted for presentation purposes
120#
121sub servername_str {
122 my ($proto, $ipver, $idnum) = @_;
124 $proto = uc($proto) if($proto);
125 die "unsupported protocol: '$proto'" unless($proto &&
126 ($proto =~ /^(((DNS|FTP|HTTP|HTTP\/2|HTTP\/3|IMAP|POP3|GOPHER|SMTP|HTTPS-MTLS)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|DICT|TELNET|MQTT|MQTTS))$/));
128 $ipver = (not $ipver) ? 'ipv4' : lc($ipver);
129 die "unsupported IP version: '$ipver'" unless($ipver &&
130 ($ipver =~ /^(4|6|ipv4|ipv6|-ipv4|-ipv6|unix)$/));
131 $ipver = ($ipver =~ /6$/) ? '-IPv6' : (($ipver =~ /unix$/) ? '-unix' : '');
133 $idnum = 1 if(not $idnum);
134 die "unsupported ID number: '$idnum'" unless($idnum &&
135 ($idnum =~ /^(\d+)$/));
136 $idnum = '' if($idnum <= 1);
138 return "${proto}${idnum}${ipver}";
139}
141#***************************************************************************
142# Return server name string formatted for identification purposes
143#
144sub servername_id {
145 my ($proto, $ipver, $idnum) = @_;
146 return lc(servername_str($proto, $ipver, $idnum));
147}
149#***************************************************************************
150# Return server name string formatted for filename purposes
151#
152sub servername_canon {
153 my ($proto, $ipver, $idnum) = @_;
154 my $string = lc(servername_str($proto, $ipver, $idnum));
155 $string =~ tr/-/_/;
156 $string =~ s/\//_v/;
157 return $string;
158}
160#***************************************************************************
161# Return filename for server pid file.
162#
163sub server_pidfilename {
164 my ($piddir, $proto, $ipver, $idnum) = @_;
165 my $trailer = '_server.pid';
166 return "${piddir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
167}
169#***************************************************************************
170# Return filename for server port file.
171#
172sub server_portfilename {
173 my ($piddir, $proto, $ipver, $idnum) = @_;
174 my $trailer = '_server.port';
175 return "${piddir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
176}
178#***************************************************************************
179# Return filename for server log file.
180#
181sub server_logfilename {
182 my ($logdir, $proto, $ipver, $idnum) = @_;
183 my $trailer = '_server.log';
184 $trailer = '_stunnel.log' if(lc($proto) =~ /^(ftp|http|imap|pop3|smtp)s$/);
185 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
186}
188#***************************************************************************
189# Return filename for server commands file.
190#
191sub server_cmdfilename {
192 my ($logdir, $proto, $ipver, $idnum) = @_;
193 my $trailer = '_server.cmd';
194 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
195}
197#***************************************************************************
198# Return filename for server input file.
199#
200sub server_inputfilename {
201 my ($logdir, $proto, $ipver, $idnum) = @_;
202 my $trailer = '_server.input';
203 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
204}
206#***************************************************************************
207# Return filename for server output file.
208#
209sub server_outputfilename {
210 my ($logdir, $proto, $ipver, $idnum) = @_;
211 my $trailer = '_server.output';
212 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
213}
215#***************************************************************************
216# Return filename for a server executable
217#
218sub server_exe {
219 my ($name, $ext) = @_;
220 if(!defined $ext) {
221 $ext = 'SRV';
222 }
223 return exerunner() . $SRVDIR . "servers" . exe_ext($ext) . " $name";
224}
226#***************************************************************************
227# Return filename for a server executable as an argument list
228#
229sub server_exe_args {
230 my ($name, $ext) = @_;
231 if(!defined $ext) {
232 $ext = 'SRV';
233 }
234 my @cmd = ($SRVDIR . "servers" . exe_ext($ext), $name);
235 if($ENV{'CURL_TEST_EXE_RUNNER'}) {
236 unshift @cmd, $ENV{'CURL_TEST_EXE_RUNNER'};
237 }
238 return @cmd;
239}
241#***************************************************************************
242# Return filename for main or primary sockfilter pid file.
243#
244sub mainsockf_pidfilename {
245 my ($piddir, $proto, $ipver, $idnum) = @_;
246 die "unsupported protocol: '$proto'" unless($proto &&
247 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
248 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.pid' : '_sockfilt.pid';
249 return "${piddir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
250}
252#***************************************************************************
253# Return filename for main or primary sockfilter log file.
254#
255sub mainsockf_logfilename {
256 my ($logdir, $proto, $ipver, $idnum) = @_;
257 die "unsupported protocol: '$proto'" unless($proto &&
258 (lc($proto) =~ /^(ftp|imap|pop3|smtp)s?$/));
259 my $trailer = (lc($proto) =~ /^ftps?$/) ? '_sockctrl.log' : '_sockfilt.log';
260 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
261}
263#***************************************************************************
264# Return filename for data or secondary sockfilter pid file.
265#
266sub datasockf_pidfilename {
267 my ($piddir, $proto, $ipver, $idnum) = @_;
268 die "unsupported protocol: '$proto'" unless($proto &&
269 (lc($proto) =~ /^ftps?$/));
270 my $trailer = '_sockdata.pid';
271 return "${piddir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
272}
274#***************************************************************************
275# Return filename for data or secondary sockfilter log file.
276#
277sub datasockf_logfilename {
278 my ($logdir, $proto, $ipver, $idnum) = @_;
279 die "unsupported protocol: '$proto'" unless($proto &&
280 (lc($proto) =~ /^ftps?$/));
281 my $trailer = '_sockdata.log';
282 return "${logdir}/" . servername_canon($proto, $ipver, $idnum) . $trailer;
283}
285#***************************************************************************
286# End of library
2871;
Diagnostics4 git calls · 59 ms
CallStatusSizeTime059 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=52 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.4 KiB · hit52 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2505 git.response.cache=HIT git.response.duration_ms=52 git.fetch.wants=427626bd55c2ee7b8cdd36883df2dc09b475d02a git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2505 git.pkt.payload.max=2484 git.sideband.band1.bytes=2483 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1ebe40922452a
- Request
- 5aa393e5…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format