Use pre-compressed file if available
authorJamie Cameron <jcameron@webmin.com>
Mon, 28 Mar 2011 04:25:53 +0000 (21:25 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 28 Mar 2011 04:25:53 +0000 (21:25 -0700)
CHANGELOG
miniserv.pl
webmin/lang/en

index 4119afc..57a78b7 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -141,5 +141,5 @@ Major Dutch updates, thanks to Gandyman.
 Majoe French translation update, thanks to ButterflyOfFire.
 Allow per-language language overrides to be defined, in custom-lang.$code files.
 Updated numerous modules to improve support for Debian 6 and Ubuntu 10.10.
-If a browser asks for gzip compression and a file with a .gz extension exists in the same directory as a static file, Webmin will now serve the gzipped file instead. If the Compress::Zlib perl module is installed and dynamic compression is enabled in the Webmin Configuration module, all non-image files will be served compressed.
+If a browser asks for gzip compression, Webmin can now return compressed content either generated dynamically or from a pre-compressed .gz file in the same directory. Dynamic compression depends on the Compress::Zlib perl module.
 Added support for Amazon Linux.
index 24e8d56..60d01ad 100755 (executable)
@@ -2438,31 +2438,6 @@ if (&get_type($full) eq "internal/cgi" && $validated != 4) {
                $rv = 0;
                }
        }
-elsif ($use_gzip && $acceptenc{'gzip'} && &should_gzip_file($full)) {
-       # Load and compress file
-       print DEBUG "handle_request: outputting gzipped file $full\n";
-       open(FILE, $full) || &http_error(404, "Failed to open file");
-       {
-               local $/ = undef;
-               $data = <FILE>;
-               }
-       close(FILE);
-       @stopen = stat($file);
-       $data = Compress::Zlib::memGzip($data);
-       local $resp = "HTTP/1.0 $ok_code $ok_message\r\n".
-                     "Date: $datestr\r\n".
-                     "Server: $config{server}\r\n".
-                     "Content-type: ".&get_type($full)."\r\n".
-                     "Content-length: ".length($data)."\r\n".
-                     "Last-Modified: ".&http_date($stopen[9])."\r\n".
-                     "Content-Encoding: gzip\r\n".
-                     "Expires: ".&http_date(time()+$config{'expires'})."\r\n";
-       &write_data($resp);
-       $rv = &write_keep_alive();
-       &write_data("\r\n");
-       &reset_byte_count();
-       &write_data($data);
-       }
 else {
        # A file to output
        print DEBUG "handle_request: outputting file $full\n";
@@ -2482,22 +2457,48 @@ else {
                open(FILE, $full) || &http_error(404, "Failed to open file");
                }
        binmode(FILE);
+
+       # Build common headers
        local $resp = "HTTP/1.0 $ok_code $ok_message\r\n".
                      "Date: $datestr\r\n".
                      "Server: $config{server}\r\n".
                      "Content-type: ".&get_type($full)."\r\n".
-                     "Content-length: $stopen[7]\r\n".
                      "Last-Modified: ".&http_date($stopen[9])."\r\n".
-                     ($gzipped ? "Content-Encoding: gzip\r\n" : "").
                      "Expires: ".&http_date(time()+$config{'expires'})."\r\n";
-       &write_data($resp);
-       $rv = &write_keep_alive();
-       &write_data("\r\n");
-       &reset_byte_count();
-       while(read(FILE, $buf, 1024) > 0) {
-               &write_data($buf);
+
+       if (!$gzipped && $use_gzip && $acceptenc{'gzip'} &&
+           &should_gzip_file($full)) {
+               # Load and compress file, then output
+               print DEBUG "handle_request: outputting gzipped file $full\n";
+               open(FILE, $full) || &http_error(404, "Failed to open file");
+               {
+                       local $/ = undef;
+                       $data = <FILE>;
+               }
+               close(FILE);
+               @stopen = stat($file);
+               $data = Compress::Zlib::memGzip($data);
+               $resp .= "Content-length: ".length($data)."\r\n".
+                        "Content-Encoding: gzip\r\n";
+               &write_data($resp);
+               $rv = &write_keep_alive();
+               &write_data("\r\n");
+               &reset_byte_count();
+               &write_data($data);
+               }
+       else {
+               # Stream file output
+               $resp .= "Content-length: $stopen[7]\r\n";
+               $resp .= "Content-Encoding: gzip\r\n" if ($gzipped);
+               &write_data($resp);
+               $rv = &write_keep_alive();
+               &write_data("\r\n");
+               &reset_byte_count();
+               while(read(FILE, $buf, 1024) > 0) {
+                       &write_data($buf);
+                       }
+               close(FILE);
                }
-       close(FILE);
        }
 
 # log the request
index 97ca0ed..10ba672 100644 (file)
@@ -793,10 +793,10 @@ advanced_nice=CPU priority for scheduled jobs
 advanced_pri=Priority level
 advanced_sclass=IO class for scheduled jobs
 advanced_sprio=IO priority for scheduled jobs
-advanced_gzip=Server gzip compressed static files?
-advanced_gzipauto=If pre-compressed .gz file exists
+advanced_gzip=Gzip compress static files?
+advanced_gzipauto=Only pre-compressed .gz file exists
 advanced_gzip0=Never
-advanced_gzip1=Always compress dynamically
+advanced_gzip1=Use pre-compressed file or compress dynamically
 advanced_egzip=Gzip compression cannot be enabled unless the $1 perl module is installed
 
 syslog_errorlog=Webmin error log