Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

JavaScript::XRay + HTTP::Proxy equals Crazy Delicious

by diotalevi (Canon)
on Jul 05, 2006 at 18:31 UTC ( #559405=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info

Blame the author of JavaScript::XRay. He demoed this at YAPC::NA 2006 but there wasn't a proxy in the distribution. I wrote this so I could use it. Just run this and set your browser to use it as a proxy. The simplest way to use this is just run it and tell your browser to use a proxy at port 8080 on your local host.

use strict;
use warnings;

=head1 NAME

jsxray-proxy - A JavaScript::XRay proxy


 jsxray [options]



Straps L<HTTP::Proxy> onto L<JavaScript::XRay> so I can use
JavaScript::XRay really easily and on arbitrary web sites.


=item -port ...

Specifies a port to listen on. The default is 8080.

=item -switches

Specifies switches to use for JavaScript::XRay. Prefix your switch wit
+h no- to pass it as a turned off switch.

=item -no-xray

Doesn't install JavaScript::XRay. It's just a simple proxy now.

=item -help

Displays the program's options.

=item -man

Displays the entire manual.



use Getopt::Long 'GetOptions';
use autouse 'Pod::Usage', 'pod2usage';

    help         => \&help,
    man          => \&man,
    'port=i'     => \( my ($port) = 8080 ),
    'switches=s' => \( my ($switches) = 'all' ),
    'no-xray'    => \my ($no_xray)
    or pod2usage( -verbose => 0 );
sub help { pod2usage( -verbose => 1 ) }
sub man  { pod2usage( -verbose => 2 ) }

require HTTP::Proxy;
my $proxy = HTTP::Proxy->new( port => $port );

if ( not $no_xray ) {
    require HTTP::Proxy::BodyFilter::simple;
    require JavaScript::XRay;

    my %switches = map { /^no-(.+)/ ? ( $1 => 0 ) : ( $_ => 1 ) }
        $switches =~ /((?:no-)?[a-z]+)/g;

    my $filter = HTTP::Proxy::BodyFilter::simple->new(
        sub {
            return unless $_[2]->header('content-type') =~ /text/;
            my $uri  = $_[2]->request->uri;
            my $xray = JavaScript::XRay->new(
                abs_uri  => $uri,
                switches => \%switches

            ${ $_[1] } = $xray->filter( ${ $_[1] } );

    $proxy->push_filter( response => $filter );


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://559405]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2020-09-30 01:12 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (156 votes). Check out past polls.