Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created December 17, 2010 07:20
Show Gist options
  • Save aanoaa/744604 to your computer and use it in GitHub Desktop.
Save aanoaa/744604 to your computer and use it in GitHub Desktop.
HTTP Message capture
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
use Time::HiRes qw[gettimeofday tv_interval];
my $time=[gettimeofday()];
unless(@ARGV>1) {
die "usage: $0 host port [document+]\n";
}
my $host=shift(@ARGV);
my $port=shift(@ARGV);
foreach my $document (@ARGV) {
my $remote=IO::Socket::INET->new(
Proto=>"tcp",
PeerAddr=>$host,
PeerPort=>$port,
);
unless($remote) {
die "cannot connect to http daemon on $host\n";
}
$remote->autoflush(1);
print $remote "GET $document HTTP/1.0\n\n";
while(<$remote>) { print }
print "\n\nelapsed time: ". elapsed_time($time)."\n";
close $remote;
}
exit;
sub elapsed_time {
my $time=shift;
return tv_interval($time)*1000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment