Created
July 22, 2015 05:29
-
-
Save vti/95cc50404d1a6f2d38ae to your computer and use it in GitHub Desktop.
HTTP::Tiny loggable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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