|
Revision 2034, 0.7 kB
(checked in by hhubner, 2 years ago)
|
Pass content-type to handling host.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
|
|---|
| 5 |
use HTTP::Daemon; |
|---|
| 6 |
use HTTP::Status; |
|---|
| 7 |
use LWP::UserAgent; |
|---|
| 8 |
|
|---|
| 9 |
my $port = "3456"; |
|---|
| 10 |
|
|---|
| 11 |
my $ua = LWP::UserAgent->new; |
|---|
| 12 |
my $daemon = HTTP::Daemon->new(LocalPort => 3456, ReuseAddr => 1); |
|---|
| 13 |
|
|---|
| 14 |
while (my $client = $daemon->accept) { |
|---|
| 15 |
my $request = $client->get_request; |
|---|
| 16 |
if ($request) { |
|---|
| 17 |
my $content = $request->content; |
|---|
| 18 |
|
|---|
| 19 |
my $is_test = ($content =~ /testMode=100/); |
|---|
| 20 |
my $host = $is_test ? "test.createrainforest.org" : "createrainforest.org"; |
|---|
| 21 |
|
|---|
| 22 |
$ua->default_header('Content-Type', $request->header('Content-Type')); |
|---|
| 23 |
my $response = $ua->get("http://" . $host . ":8080/handle-sale?" . $content); |
|---|
| 24 |
$client->send_response($response); |
|---|
| 25 |
print "Redirected request to ", ($is_test ? "TEST" : "PRODUCTION"), " system\n"; |
|---|
| 26 |
} |
|---|
| 27 |
$client->close; |
|---|
| 28 |
} |
|---|