[pve-devel] [PATCH] avoid gzip http response for png & gif

Alexandre Derumier aderumier at odiso.com
Mon Jun 10 14:07:17 CEST 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/HTTPServer.pm |    9 ++++++---
 PVE/REST.pm       |    6 +++---
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
index 46c217e..6911b10 100755
--- a/PVE/HTTPServer.pm
+++ b/PVE/HTTPServer.pm
@@ -264,14 +264,17 @@ sub send_file_start {
 	    die "got short file\n" if !defined($len) || $len != $stat->size;
 
 	    my $ct;
+	    my $nocomp;
 	    if ($filename =~ m/\.css$/) {
 		$ct = 'text/css';
 	    } elsif ($filename =~ m/\.js$/) {
 		$ct = 'application/javascript';
 	    } elsif ($filename =~ m/\.png$/) {
 		$ct = 'image/png';
+		$nocomp = 1;
 	    } elsif ($filename =~ m/\.gif$/) {
 		$ct = 'image/gif';
+		$nocomp = 1;
 	    } elsif ($filename =~ m/\.jar$/) {
 		$ct = 'application/java-archive';
 	    } else {
@@ -280,7 +283,7 @@ sub send_file_start {
 
 	    my $header = HTTP::Headers->new(Content_Type => $ct);
 	    my $resp = HTTP::Response->new(200, "OK", $header, $data);
-	    $self->response($reqstate, $resp, $mtime);
+	    $self->response($reqstate, $resp, $mtime, $nocomp);
 	};
 	if (my $err = $@) {
 	    $self->error($reqstate, 501, $err);
@@ -459,12 +462,12 @@ sub handle_api2_request {
 	}
 
 	PVE::REST::prepare_response_data($format, $res);
-	my ($raw, $ct) = PVE::REST::format_response_data($format, $res, $path);
+	my ($raw, $ct, $nocomp) = PVE::REST::format_response_data($format, $res, $path);
 
 	my $resp = HTTP::Response->new($res->{status}, $res->{message});
 	$resp->header("Content-Type" => $ct);
 	$resp->content($raw);
-	$self->response($reqstate, $resp);
+	$self->response($reqstate, $resp, $nocomp);
     };
     if (my $err = $@) {
 	$self->error($reqstate, 501, $err);
diff --git a/PVE/REST.pm b/PVE/REST.pm
index c570daf..d59f88d 100644
--- a/PVE/REST.pm
+++ b/PVE/REST.pm
@@ -49,7 +49,7 @@ sub format_response_data {
     my $data = $res->{data};
     my $info = $res->{info};
 
-    my ($ct, $raw);
+    my ($ct, $raw, $nocomp);
 
     if ($format eq 'json') {
 	$ct = 'application/json;charset=UTF-8';
@@ -92,7 +92,7 @@ sub format_response_data {
 
     } elsif ($format eq 'png') {
 	$ct = 'image/png';
-
+	$nocomp = 1;
 	# fixme: better to revove that whole png thing ?
 
 	my $filename;
@@ -116,7 +116,7 @@ sub format_response_data {
 	$raw = to_json($data, {utf8 => 1, allow_nonref => 1, pretty => 1});
     }
 
-    return wantarray ? ($raw, $ct) : $raw;
+    return wantarray ? ($raw, $ct, $nocomp) : $raw;
 }
 
 sub prepare_response_data {
-- 
1.7.10.4




More information about the pve-devel mailing list