Skip to content

Commit

Permalink
Fixed strange issue with decoded_content
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinbjornt committed May 21, 2013
1 parent 64d34f7 commit 6e209b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
17 changes: 14 additions & 3 deletions perl/DataURL/CSS.pm
Expand Up @@ -56,17 +56,27 @@ sub optimize
}

my $css_size = $response->header('content-length');
if ($css_size > $max_css_size)
if ($css_size && $css_size > $max_css_size)
{
return _error("CSS size ($css_size) exceeds maximum ($max_css_size)");
}

# OK, the file seems fine. Let's fetch it properly using GET.
$request = HTTP::Request->new(GET => $css_url);
$response = $ua->request($request);

if (!$response->is_success)
{
return _error("Failed to fetch CSS document. Status: " . $response->status_line);
}

# Get content
my $css = $response->decoded_content();
my $css = $response->content();

if (!length($css))
{
return _error("Remote file is empty. Status: " . $response->status_line);
}

# Find and clean all strings contained within url()
my (@matches) = $css =~ m/url\s?\(\s?"?'?(\s?.+\s?)'?"?\)/ig;
Expand Down Expand Up @@ -280,6 +290,7 @@ sub _error
{
my ($msg) = @_;
my %reply = ( 'error' => $msg );
warn($msg);
return \%reply;
}

Expand Down
2 changes: 1 addition & 1 deletion update_deployment.sh
@@ -1,6 +1,6 @@
#!/bin/sh

rsync -az --progress -rvv --force web/* root@dataurl.net:/www/dataurl
rsync -az --progress -rvv --exclude web/tmp/log.db --force web/* root@dataurl.net:/www/dataurl
rsync -az --progress -rvv --force perl/* root@dataurl.net:/www/dataurl/cgi-bin/

# Use minifier script to minify HTML
Expand Down
14 changes: 10 additions & 4 deletions web/cgi-bin/dataurl.pl
Expand Up @@ -14,17 +14,22 @@
use Data::Validate::URI qw(is_http_uri is_https_uri);
use SQLiteLogger;

use vars qw($logdb $tmp_public_dir); # Shared dictionary of databases


my $dataurlmaker_hardlimit = 250 * 1024;
my $tmp_public_dir = '/www/dataurl/html/tmp/';
$tmp_public_dir = '/www/dataurl/html/tmp/';


use vars qw($logdb); # Shared dictionary of databases

if (!defined($logdb))
if (!$logdb)
{
$logdb = new SQLiteLogger;
if (!$logdb) { error("Could not connect to database.", '200 OK'); }
}

if (!$logdb) { error("Could not connect to database.", '200 OK'); }


local our $remote_ip = $ENV{'REMOTE_ADDR'};
local our $user_agent = $ENV{'HTTP_USER_AGENT'};

Expand Down Expand Up @@ -119,6 +124,7 @@ sub reply
print "Status: $status\n";
print STDOUT "Content-Type: application/json\n\n";
print STDOUT $json;

$logdb->Log($status, defined($hashref->{error}), time(), $remote_ip, $json);

exit(0);
Expand Down

0 comments on commit 6e209b4

Please sign in to comment.