Comments on: Compressed HTTP https://grey-panther.net/2007/07/compressed-http.html Just another WordPress site Wed, 22 Apr 2009 09:35:05 +0000 hourly 1 https://wordpress.org/?v=6.9.4 By: Anonymous https://grey-panther.net/2007/07/compressed-http.html#comment-415 Wed, 22 Apr 2009 09:35:05 +0000 https://grey-panther.net/?p=842#comment-415 Fantastic solution. I used mod_deflate to uncompress the posted data. If you use a perl CGI handler on the receiving end the Content-Length header does not match that of the content (why mod deflate doesn't fix this I don't know?) – So I added an additional header:-

sub transform_upload {
my $request = shift;

my $origLen = 0;
my $fh = new File::Temp;
my $filename = $fh->filename;
print "Temp file is $filenamen";
my $cs = gzopen($fh, "wb");
my $request_c = $request->content();
while (my $data = $request_c->()) {
$cs->gzwrite($data);
$origLen += length($data);
}
$cs->gzclose();

$fh = new FileHandle("<$filename");
$request->content(sub {
my $buffer;
if (0 < read $fh, $buffer, 4096) {
return $buffer;
} else {
close $fh;
return undef;
}
});
$request->content_length(-s $filename);
$request->headers->header('X-Uncompressed-Length' => $origLen);
}

Then the CGI script should have the following added before the CGI constructor:-
#
# As apache has nicely uncompressed the content
# it DID NOT change the Content-Length header
# So we use a frig to get round this done by the client
#
$ENV{CONTENT_LENGTH} = $ENV{HTTP_X_UNCOMPRESSED_LENGTH}
if $ENV{HTTP_X_UNCOMPRESSED_LENGTH};

my $q = new CGI;

This ensured the compression is seamless.

]]>
By: Anonymous https://grey-panther.net/2007/07/compressed-http.html#comment-674 Sat, 27 Sep 2008 17:46:03 +0000 https://grey-panther.net/?p=842#comment-674 How can I test this perl script? (sorry i am not familiare with perl)
Thanks!

]]>
By: Cory R. King https://grey-panther.net/2007/07/compressed-http.html#comment-730 Tue, 29 Apr 2008 05:42:55 +0000 https://grey-panther.net/?p=842#comment-730 This post saved me a bit of time, thanks!

If you are a mod_perl2 (or mod_perl) guy, you’ll hit a similar problem to the one you describe.

Make sure to set the content-length (set_content_length) and *do NOT call rflush!!!!*. If you rflush() before or after you print() your content, mod_deflate will drop the content-length header!!

]]>
By: Cd-MaN https://grey-panther.net/2007/07/compressed-http.html#comment-744 Sun, 06 Apr 2008 16:46:16 +0000 https://grey-panther.net/?p=842#comment-744 Very interesting. Does anybody know if any HTTP libraries / client programs (ie. Perl’s LWP, wget, curl, etc) implement this approach?

Also, this shows just how complex “simple” protocols like HTTP or MIME have become.

]]>
By: Anonymous https://grey-panther.net/2007/07/compressed-http.html#comment-748 Sun, 06 Apr 2008 11:34:36 +0000 https://grey-panther.net/?p=842#comment-748 It can be negotiated. Add “Expect: 100-continue” header to the request that has “Content-Encoding: deflate”. If the server responds with a “100 continue” then go ahead and send the compressed version. Otherwise, remove the “Expect” and “Content-Encoding” headers and send the uncompressed version.

]]>
By: Cd-MaN https://grey-panther.net/2007/07/compressed-http.html#comment-762 Sun, 02 Dec 2007 15:39:06 +0000 https://grey-panther.net/?p=842#comment-762 I don’t think it will work. As far as I know mod_gzip is the predecessor of mod_deflate (ie. it was used for Apache 1.3) and it’s no longer available for Apache 2.0 or 2.2.

]]>
By: Jason Jones https://grey-panther.net/2007/07/compressed-http.html#comment-764 Sun, 02 Dec 2007 14:11:51 +0000 https://grey-panther.net/?p=842#comment-764 Do you have any idea if compressing uploads (POST data) is supported by mod_gzip? I haven’t been able to find anything that indicates that it is.

]]>