App-cdnget
view release on metacpan or search on metacpan
lib/App/cdnget/Downloader.pm view on Meta::CPAN
sub processHook_img
{
my $self = shift;
my ($hook, $response, @params) = @_;
my $headers = $response->{_headers};
my $img;
given ($headers->content_type)
{
when ("image/png")
{
$img = GD::Image->newFromPngData($response->decoded_content) or $self->throw($!);
}
when ("image/jpeg")
{
$img = GD::Image->newFromJpegData($response->decoded_content) or $self->throw($!);
}
default
{
$self->throw("Unsupported content type for image");
}
}
given ($hook)
{
when (/^imgresize$/i)
{
lib/App/cdnget/Downloader.pm view on Meta::CPAN
sub processHook_css
{
my $self = shift;
my ($hook, $response, @params) = @_;
my $headers = $response->{_headers};
$self->throw("Unsupported content type for css") unless $headers->content_type =~ /^(text\/css|application\/x\-pointplus)$/;
given ($hook)
{
when (/^cssminify$/i)
{
my $data = CSS::Minifier::XS::minify($response->decoded_content);
return ("Status: 200\r\nContent-Type: ".$headers->content_type."\r\nContent-Length: ".length($data)."\r\n", $data);
}
default
{
$self->throw("Unsupported css hook");
}
}
return;
}
sub processHook_js
{
my $self = shift;
my ($hook, $response, @params) = @_;
my $headers = $response->{_headers};
$self->throw("Unsupported content type for js") unless $headers->content_type =~ /^(text\/javascript|text\/ecmascript|application\/javascript|application\/ecmascript|application\/x\-javascript)$/;
given ($hook)
{
when (/^jsminify$/i)
{
my $data = JavaScript::Minifier::XS::minify($response->decoded_content);
return ("Status: 200\r\nContent-Type: ".$headers->content_type."\r\nContent-Length: ".length($data)."\r\n", $data);
}
default
{
$self->throw("Unsupported js hook");
}
}
return;
}
lib/App/cdnget/Downloader.pm view on Meta::CPAN
);
$matchspec{':content_cb'} = $content_cb;
}
my $response = $ua->get($self->url, %matchspec);
die $response->header("X-Died")."\n" if $response->header("X-Died");
$self->throw("Download failed") if $response->header("Client-Aborted");
unless ($self->hook)
{
unless ($response->is_success)
{
$content_cb->($response->decoded_content, $response);
}
} else
{
if ($response->is_success)
{
my ($header, $data) = $self->processHook($response);
if ($header)
{
$header .= "Client-URL: ".$self->url."\r\n";
$header .= "Client-Hook: ".$self->hook."\r\n";
$header .= "Client-Date: ".POSIX::strftime($App::cdnget::DTF_RFC822_GMT, gmtime)."\r\n";
$data = "" unless defined($data);
$fh->print($header."\r\n".$data) or $self->throw($!);
}
} else
{
$response_header->($response, $ua);
$content_cb->($response->decoded_content, $response);
}
}
};
do
{
local $@;
$fh->close();
{
lock(%uids);
delete($uids{$self->uid});
( run in 0.482 second using v1.01-cache-2.11-cpan-26ccb49234f )