From b7d9256a7a673ec38da2448d9de879bfd7d1e9e4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 16 Sep 2009 22:34:35 +0200 Subject: tests:webclient: add a --dry-run mode that prints the request to stdout and does not connect to the server at all. Michael --- tests/scripts/webclient.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/scripts/webclient.pl') diff --git a/tests/scripts/webclient.pl b/tests/scripts/webclient.pl index f76dbd9..84d8790 100755 --- a/tests/scripts/webclient.pl +++ b/tests/scripts/webclient.pl @@ -32,6 +32,7 @@ my $user_agent = "$NAME/$VERSION"; my $user_agent_header = "User-Agent: $user_agent$EOL"; my $http_version = 1.0; my $method = "GET"; +my $dry_run = 0; my $help = 0; my $default_port = "80"; @@ -40,7 +41,8 @@ my $port = $default_port; sub process_options() { my $result = GetOptions("help|?" => \$help, "http-version=s" => \$http_version, - "method=s" => \$method); + "method=s" => \$method, + "dry-run" => \$dry_run); die "Error reading cmdline options! $!" unless $result; pod2usage(1) if $help; @@ -99,6 +101,12 @@ if ($host =~ /^([^:]+):(.*)/) { } foreach my $document (@ARGV) { + my $request = build_request($host, $port, $http_version, $method, $document); + if ($dry_run) { + print $request; + exit(0); + } + my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, @@ -110,7 +118,7 @@ foreach my $document (@ARGV) { $remote->autoflush(1); - print $remote build_request($host, $port, $http_version, $method, $document); + print $remote $request; while (<$remote>) { print; @@ -147,6 +155,10 @@ Specify the HTTP protocol version to use (0.9, 1.0, 1.1). Default is 1.0. Specify the HTTP request method ('GET', 'CONNECT', ...). Default is 'GET'. +=item B<--dry-run> + +Don't actually connect to the server but print the request that would be sent. + =back =head1 DESCRIPTION -- cgit v1.2.3