Skip to content

Instantly share code, notes, and snippets.

@gugod
Created November 14, 2008 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugod/24716 to your computer and use it in GitHub Desktop.
Save gugod/24716 to your computer and use it in GitHub Desktop.
#!/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
| google
| 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