Apache-Gateway
view release on metacpan or search on metacpan
my ($self, $response, $allow_abort) = @_;
my $r = $self->{REQUEST};
my $site = $self->{SITE};
my $path = $self->{GW_PATH};
# Copy status code and reason phrase from response to Apache
# request.
$r->status($1) if $response->status_line =~ /^(\d+)/;
$r->status_line($response->status_line);
# Attempt to abort on failure.
return if $allow_abort && $response->is_error;
# $r->log_error('Gateway: ' . $response->request->url
# . ' ' . $response->status_line);
# configuration info for this directory
my $loc_conf = $self->location_config;
# Try to modify Content-Base to refer to our multiplexer.
if(my $base = $response->header('Content-Base')) {
# where site appears on gateway, e.g., <http://www.perl.com/CPAN/>.
my $gw_site = server_name($r) . $loc_conf->{ROOT};
$response->header(Content_Base => $base)
if $base =~ s/^$site/$gw_site/;
}
# If necessary, try to compensate for servers with broken clocks.
if(my $lm = $response->last_modified) {
my $upstream_server = server_name_from_URL($r,
$response->request->url->as_string);
if(exists $loc_conf->{BROKEN_CLOCK}{$upstream_server}) {
my $TZ = $loc_conf->{BROKEN_CLOCK}{$upstream_server};
$response->last_modified($lm + diff_TZ($$TZ[1], $$TZ[0]));
}
}
$self->update_via_header_field($response);
copy_header_to_Apache_request($r, $response);
$r->send_http_header;
}
=item redirect($allow_abort);
Try a redirect. We do this via C<LWP::UserAgent> because
C<internal_redirect_handler> does not provide hooks for detecting and
recovering from errors.
=cut
sub redirect($$) {
my ($self, $allow_abort) = @_;
my $r = $self->{REQUEST};
my $ua = $self->{UA};
my $site = $self->{SITE};
my $path = $self->{GW_PATH};
my $url = Apache::URI->parse($r, $site . $path);
# If this is an anon-FTP request, fill in the password with the
# UA's from field.
if($url->scheme eq 'ftp' && $url->user eq 'anonymous') {
$url->password($ua->from) # anon-FTP passwd
}
my $request = HTTP::Request->new($r->method, $url->unparse);
# If upstream server has a broken clock, calculate how much we
# need to adjust condition GET time fields. Note: this code won't
# work correctly if we get redirected to another server with a
# different clock. Oh, well.
my $loc_conf = $self->location_config;
my $upstream_server = server_name_from_URL($r, $url);
my $broken_clock = 0;
if(exists $loc_conf->{BROKEN_CLOCK}{$upstream_server}) {
my $TZ = $loc_conf->{BROKEN_CLOCK}{$upstream_server};
$broken_clock = diff_TZ($$TZ[1], $$TZ[0]);
}
if(my $IMS = $r->header_in('If-Modified-Since')) {
$request->if_modified_since(HTTP::Date::str2time($IMS)
- $broken_clock);
}
if(my $IUmS = $r->header_in('If-Unmodified-Since')) {
$request->if_unmodified_since(HTTP::Date::str2time($IUmS)
- $broken_clock);
}
$request->header(Accept => $r->header_in('Accept'));
# Pragma directives must be passed through.
if(my $pragma = $r->header_in('Pragma')) {
$request->header($pragma);
$request->header('Cache-Control' => 'no-cache') # HTTP/1.1
if $pragma =~ /^no-cache$/i;
}
# Cache directives must be passed through.
if(my $cache = $r->header_in('Cache-Control')) {
$request->header('Cache-Control' => $cache);
}
# We would like the first callback to occur as soon as reasonably
# possible after the headers have been retrieved. Thus, we need a
# small size argument because the first callback may not occur
# until all the headers plus size bytes of the content have been
# retrieved.
my $headers_printed;
my $response = $ua->request($request,
sub {
my($data, $response) = @_;
$self->print_headers($response, $allow_abort)
unless $headers_printed;
$headers_printed = 1;
return if($allow_abort && $response->is_error
|| $r->connection->aborted);
$r->print($data);
},
1024);
# Be sure we've printed the headers. We need this check here
# because callback will never get called for responses with no
( run in 1.645 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )