Skip to content

Instantly share code, notes, and snippets.

@vti
Created July 22, 2015 05:29
Show Gist options
  • Save vti/95cc50404d1a6f2d38ae to your computer and use it in GitHub Desktop.
Save vti/95cc50404d1a6f2d38ae to your computer and use it in GitHub Desktop.
HTTP::Tiny loggable
use strict;
use warnings;
use HTTP::Tiny;
{
my $ua = HTTP::Tiny->new();
my $request = '';
my $response = '';
no warnings 'redefine';
my $super_write = \&HTTP::Tiny::Handle::write;
local *HTTP::Tiny::Handle::write = sub {
my (undef, $buf) = @_;
warn 'HERE';
$request .= $buf;
$super_write->(@_);
};
my $super_readline = \&HTTP::Tiny::Handle::readline;
local *HTTP::Tiny::Handle::readline = sub {
my $buf = $super_readline->(@_);
warn 'THERE';
$response .= $buf;
return $buf;
};
#my $super_read = \&HTTP::Tiny::Handle::read;
#*HTTP::Tiny::Handle::read = sub {
#my $buf = $super_read->(@_);
#$response .= $buf;
#return $buf;
#};
#$ua->get('http://showmetheco.de');
#warn $request;
#warn "[$response]";
}
my $ua = HTTP::Tiny->new();
$ua->get('http://showmetheco.de');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment