Created
November 14, 2008 01:26
-
-
Save gugod/24716 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use HTTP::Proxy; | |
use HTTP::Proxy::HeaderFilter::simple; | |
my $proxy = HTTP::Proxy->new(port => 3128); | |
$proxy->push_filter( | |
request =>HTTP::Proxy::HeaderFilter::simple->new( | |
sub { | |
my ( $self, $headers, $message ) = @_; | |
my $host = $message->uri()->host(); | |
unless ( | |
$message->uri()->port() != 80 || | |
$host =~ /( | |
\.nyud\.net | |
| ( google-analytics | |
| googlesyndication | |
| flickr | |
| mac )\.com | |
)$/x | |
) { | |
$host .= ".nyud.net"; | |
$message->uri()->host($host); | |
$headers->header(Host => $host); | |
print "==> " . $message->uri()->as_string . "\n"; | |
} | |
} | |
), | |
response => HTTP::Proxy::HeaderFilter::simple->new( | |
sub { | |
my ($self, $headers, $message) = @_; | |
if ($message->code == 302) { | |
my $location = $headers->header('Location'); | |
$location =~ s/\.nyud\.net//; | |
$headers->header(Location => $location); | |
} | |
} | |
) | |
); | |
$proxy->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment