summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-02-21 18:23:41 +0100
committerfranck cuny <franck@lumberjaph.net>2011-07-26 13:19:59 +0200
commitcadf7b3571dfbe957759b3ec6e5af066dc71ac2b (patch)
tree66532ff2f6f59a2338b1da72b13e2290a766d34e
parentbasic code to log (diff)
downloadnet-http-spore-cadf7b3571dfbe957759b3ec6e5af066dc71ac2b.tar.gz
log request and respose
-rw-r--r--lib/Net/HTTP/Spore/Role/Request.pm29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/Net/HTTP/Spore/Role/Request.pm b/lib/Net/HTTP/Spore/Role/Request.pm
index 832549d..c900610 100644
--- a/lib/Net/HTTP/Spore/Role/Request.pm
+++ b/lib/Net/HTTP/Spore/Role/Request.pm
@@ -67,11 +67,11 @@ sub _execute_middlewares_on_response {
 sub _request {
     my ($self, $request) = @_;
 
-    my $req_final = $request->finalize();
+    my $finalized_request = $request->finalize();
 
-    $self->_trace_msg( $req_final->method . ' ' . $req_final->url );
+    $self->_debug_request($request, $finalized_request);
 
-    my $result = $self->request($req_final);
+    my $result = $self->request($finalized_request);
 
     my $response = $request->new_response(
         $result->code,
@@ -79,9 +79,32 @@ sub _request {
         $result->content,
     );
 
+    $self->_debug_response($response);
+
     return $response;
 }
 
+sub _debug_request {
+    my ( $self, $request, $finalized_request ) = @_;
+    return unless $self->trace;
+
+    $self->_trace_msg( '> %s %s', $request->method, $request->path );
+    $self->_trace_msg( '> Host: %s', $request->host );
+    foreach my $key ( $request->headers->header_field_names ) {
+        $self->_trace_msg( '> %s: %s', $key, $request->header($key) );
+    }
+}
+
+sub _debug_response {
+    my ($self, $response) = @_;
+    return unless $self->trace;
+
+    foreach my $key ( $response->headers->header_field_names ) {
+        $self->_trace_msg( '< %s: %s', $key, $response->header($key) );
+    }
+    $self->_trace_verbose($response->body);
+}
+
 1;
 
 =head1 SYNOPSIS