--- Recorder.old 2005-11-01 13:56:10.155897600 -0600 +++ Recorder.pm 2005-09-27 11:48:12.000000000 -0500 @@ -87,11 +87,12 @@ use strict; use warnings; use LWP::UserAgent; + use HTML::TokeParser; use HTTP::Recorder::Logger; use URI::Escape qw(uri_escape uri_unescape); use URI::QueryParam; -use HTTP::Request::Params; +use HTTP::Recorder::Request; our @ISA = qw( LWP::UserAgent ); @@ -182,12 +183,15 @@ my $response; + # make a HTTP::Recorder::Request object + my $newrequest = HTTP::Recorder::Request->new(request => $request, + prefix => $self->{prefix}); + # special handling if the URL is the control URL - if ($request->uri->host eq $self->{control}) { + if ($newrequest->uri->host eq $self->{control}) { # get the arguments passed from the form - my $arghash; - $arghash = extract_values($request); + my $arghash = $newrequest->get_params; # there may be an action we need to perform if (exists $arghash->{updatescript}) { @@ -226,11 +230,39 @@ $content, ); } else { - $request = $self->modify_request ($request) - unless $self->{ignore_favicon} - && $request->uri->path =~ /favicon\.ico$/i; + my $values = $newrequest->get_params; + my $action = $values->{"$self->{prefix}-action"}; + if ( $self->{ignore_favicon} && + $newrequest->uri->path =~ /favicon\.ico$/i) { + # don't do anything + } elsif (!$action) { + $newrequest->unmodify_query(); + + if (!$newrequest->headers->referer) { + + # log a blank line to give the code a little breathing room + $self->{logger}->LogLine(); + $self->{logger}->GotoPage(url => $newrequest->uri); + } + } else { + $self->log_actions($values, $action); + + # undo what we've done + $newrequest->unmodify_query(); + } + + my $https = $values->{"$self->{prefix}-https"}; + if ( $https && $https == 1) { + my $uri = $newrequest->uri; + $uri->scheme('https') if $uri->scheme eq 'http'; + + $newrequest = new HTTP::Request($newrequest->method, + $uri, + $newrequest->headers, + $newrequest->content); + } - $response = $self->SUPER::send_request( $request ); + $response = $self->SUPER::send_request( $newrequest ); my $content_type = $response->headers->header('Content-type') || ""; @@ -243,25 +275,15 @@ return $response; } -sub modify_request { +sub log_actions { my $self = shift; - my $request = shift; + my $values = shift; + my $action = shift; - my $values = extract_values($request); + return unless $action; # log the actions - my $action = $values->{"$self->{prefix}-action"}; - - my $referer = $request->headers->referer; - if (!$action) { - if (!$referer) { - my $uri = $self->unmodify($request->uri);; - - # log a blank line to give the code a little breathing room - $self->{logger}->LogLine(); - $self->{logger}->GotoPage(url => $uri); - } - } elsif ($action eq "follow") { + if ($action eq "follow") { $self->{logger}->FollowLink(text => $values->{"$self->{prefix}-text"} || "", index => $values->{"$self->{prefix}-index"} || "", url => $values->{"$self->{prefix}-url"}); @@ -309,62 +331,6 @@ $self->{logger}->LogLine(); } - # undo what we've done - $request->uri($self->unmodify($request->uri)); - $request->content($self->unmodify($request->content)); - - # reset the Content-Length (if needed) to prevent warnings from - # HTTP::Protocol - if ($action && ($action eq "submitform")) { - $request->headers->header('Content-Length' => length($request->content()) ); - - } - - my $https = $values->{"$self->{prefix}-https"}; - if ( $https && $https == 1) { - my $uri = $request->uri; - $uri->scheme('https') if $uri->scheme eq 'http'; - - $request = new HTTP::Request($request->method, - $uri, - $request->headers, - $request->content); - - } - - return $request; -} - -sub unmodify { - my $self = shift; - my $content = shift; - - return $content unless $content; - - # get rid of the arguments we added - my $prefix = $self->{prefix}; - - for my $key ($content->query_param) { - if ($key =~ /^$prefix-/) { - $content->query_param_delete($key); - } - } - return $content; -} - -sub extract_values { - my $request = shift; - - my $parser = HTTP::Request::Params->new({ - req => $request, - }); - - # un-escape all params - for my $key (keys %{$parser->params}) { - $parser->params->{$key} = uri_unescape($parser->params->{$key}); - } - - return $parser->params; } sub modify_response { @@ -565,7 +531,7 @@ $fields .= ("{prefix}-formname\" value=\"$name\">\n"); $fields .= ("{prefix}-formnumber\" value=\"$number\">\n"); if ($https) { - $fields .= ("{prefix}-https\" value=\"$https\">\n"); + $fields .= ("{prefix}-https\" value=\"$https\">\n"); } return $fields; @@ -586,7 +552,7 @@

Start Recording

-

Type a url into the browser's adddress field to begin recording. +

Type a url into the browser adddress field to begin recording. EOF @@ -682,12 +648,12 @@ my $js = <, including browsing the current source tree, at http://www.bitmistress.org/. -There's a mailing list for users and developers of HTTP::Recorder. -You can subscribe at +You can subscribe to the mailing list for users and developers of +HTTP::Recorder at http://lists.fsck.com/mailman/listinfo/http-recorder, or by sending email to http-recorder-request@lists.fsck.com with the subject "subscribe". @@ -749,7 +715,7 @@ Copyright 2003-2005 by Linda Julien Released under the GNU Public License. - +' =cut 1;