my $ua = LWP::UserAgent->new(timeout => 180,); $ua->env_proxy; my $rsp = $ua->head($new_route); send_error('Bad Gateway (head)', 502) unless (ref $rsp && $rsp->is_success); foreach my $key ('Content-Encoding', 'Content-Length', 'Content-Type', 'Last-Modified') { my $value = $rsp->header($key) || ''; header($key => $value) if ($value); } $rsp = $ua->get($new_route); send_error('Bad Gateway (get)', 502) unless (ref $rsp && $rsp->is_success); return $rsp->content;