You have two servers, A1.com and A2.com, and A2.com is the backup mirror of A1.com. You want to make one HTTP request to A2.com but pretend that the DNS resolves A1.com to its IP. This snippet allows you that, by taking over the creation of new IO::Socket objects.
The correct Host: header for A1.com is still sent, so name-based virtual hosting works as it should, too.
Update: Failover is also a good keyword for this node...
use strict; use IO::Socket::INET; use LWP::Simple; my $url = 'http://www.google.com'; my $backup_host = 'www.apache.org'; getprint $url; { my $old_constructor = \&IO::Socket::INET::new; local *IO::Socket::INET::new = sub { my ($package,%args) = @_; warn "Redirecting from $args{PeerAddr} to $backup_host"; $args{PeerAddr} = $backup_host; $old_constructor->($package,%args); }; getprint $url; };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Direct a LWP connection to a different host
by Aristotle (Chancellor) on Jan 30, 2005 at 22:57 UTC | |
Re: Direct a LWP connection to a different host
by hossman (Prior) on Jan 31, 2005 at 07:25 UTC | |
by Aristotle (Chancellor) on Jan 31, 2005 at 07:40 UTC | |
by Corion (Patriarch) on Jan 31, 2005 at 07:45 UTC | |
by Aristotle (Chancellor) on Jan 31, 2005 at 07:56 UTC | |
by hossman (Prior) on Jan 31, 2005 at 08:18 UTC | |
Re: Direct a LWP connection to a different host
by thospel (Hermit) on Jan 31, 2006 at 15:36 UTC |