Hi 2 all. I'm trying to implement some sort of repeater for my needs. As a test appliance it should detect google captcha request in response on search request. I mean if request is:

http://www.google.com/search?=perlmonks

and search engine will respond

http://www.google.com/sorry/?continue=http://www.google.com/search%3Fq%3Fperlmonks

Custom proxy must:

1. Detect this response by "/sorry/"

2. Turn it into initial request again :

http://www.google.com/search?=perlmonks

3. Redirect client on

http://www.google.com/search?=perlmonks

I'm new to perl, so this code may contain mistakes:
#!/usr/bin/perl use strict; use warnings; use HTTP::Proxy qw( :log ); use HTTP::Proxy::HeaderFilter::simple; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); $ua->proxy(['http'],'http://127.0.0.1:29999'); $ua->timeout(10); $ua->agent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, li +ke Gecko) Chrome/11.0.696.60 Safari/534.24'); #open ( LOGFILE, ">>", "/var/log/repeater.log"); my $fname = "/var/log/repeater.log"; open my $logfh, ">>", $fname or die "couldn't open '$fname': $!"; my $proxy = HTTP::Proxy->new( port => '38374', agent => $ua, logfh => $logfh, @ARGV ); #HTTP::Proxy->new(@ARGV); ### <------- Is there any method that will +allow to pass @ARGV or something else if new() method was used earlie +r. $proxy->logmask( ALL ); $proxy->push_filter( # host => 'google.com', # only apply to this domain response => HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $s +elf, $headers, $response ) = @_; # skip non redirects return if $response->code !~ /^3/; # pick up location my $location = $headers->header('Location'); # find bad redirections if ( $location =~ m{\/sorry.*} ) { # change the redirect my $new_location = $location ; $new_location =~ s/.*(\/sorry\/\?continue=.*)/$1/gx ; $new_location =~ s/\/sorry\/\?continue=//; $headers->header( Location => $new_location ); # print some logging information $self->proxy->log( ALL, LOCATION => "$location => $new_location" ); } } ) ); $proxy->start;
The thing is, I've allready used new() method for some parameters, but now I need to pass @ARGV. I can't finish this script due to a lack of experience but I really need this thing to work :(. Thanks in advance.

In reply to Unfinished custom proxy by kazak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.