Make expiry time customizable on a per-file basis
authorJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:25:34 +0000 (15:25 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:25:34 +0000 (15:25 -0700)
miniserv.pl
webmin/CHANGELOG
webmin/change_web.cgi
webmin/edit_web.cgi
webmin/lang/en

index 1db1fbe..0b4f2a2 100755 (executable)
@@ -2466,7 +2466,8 @@ else {
                      "Server: $config{server}\r\n".
                      "Content-type: ".&get_type($full)."\r\n".
                      "Last-Modified: ".&http_date($stopen[9])."\r\n".
-                     "Expires: ".&http_date(time()+$config{'expires'})."\r\n";
+                     "Expires: ".
+                       &http_date(time()+&get_expires_time($simple))."\r\n";
 
        if (!$gzipped && $use_gzip && $acceptenc{'gzip'} &&
            &should_gzip_file($full)) {
@@ -4264,7 +4265,7 @@ my %vital = ("port", 80,
          "maxconns", 50,
          "pam", "webmin",
          "sidname", "sid",
-         "unauth", "^/unauthenticated/ ^/robots.txt\$ ^[A-Za-z0-9\\-/_]+\\.jar\$ ^[A-Za-z0-9\\-/_]+\\.class\$ ^[A-Za-z0-9\\-/_]+\\.gif\$ ^[A-Za-z0-9\\-/_]+\\.conf\$ ^[A-Za-z0-9\\-/_]+\\.ico\$ ^/robots.txt\$",
+         "unauth", "^/unauthenticated/ ^/robots.txt\$ ^[A-Za-z0-9\\-/_]+\\.jar\$ ^[A-Za-z0-9\\-/_]+\\.class\$ ^[A-Za-z0-9\\-/_]+\\.gif\$ ^[A-Za-z0-9\\-/_]+\\.png\$ ^[A-Za-z0-9\\-/_]+\\.conf\$ ^[A-Za-z0-9\\-/_]+\\.ico\$ ^/robots.txt\$",
          "max_post", 10000,
          "expires", 7*24*60*60,
          "pam_test_user", "root",
@@ -4781,6 +4782,15 @@ foreach my $d (split(/\s+/, $config{'davpaths'})) {
 @mobile_agents = split(/\t+/, $config{'mobile_agents'});
 @mobile_prefixes = split(/\s+/, $config{'mobile_prefixes'});
 
+# Expires time list
+@expires_paths = ( );
+foreach my $pe (split(/\t+/, $config{'expires_paths'})) {
+       my ($p, $e) = split(/=/, $pe);
+       if ($p && $e ne '') {
+               push(@expires_paths, [ $p, $e ]);
+               }
+       }
+
 # Open debug log
 close(DEBUG);
 if ($config{'debug'}) {
@@ -5784,3 +5794,16 @@ my ($path) = @_;
 return $path !~ /\.(gif|png|jpg|jpeg|tif|tiff)$/i;
 }
 
+# get_expires_time(path)
+# Given a URL path, return the client-side expiry time in seconds
+sub get_expires_time
+{
+my ($path) = @_;
+foreach my $pe (@expires_paths) {
+       if ($path =~ /$pe->[0]/i) {
+               return $pe->[1];
+               }
+       }
+return $config{'expires'};
+}
+
index 0e99965..619cb7c 100644 (file)
@@ -106,3 +106,4 @@ Added the Sending Email page which controls how Webmin itself sends messages.
 ---- Changes since 1.550 ----
 Added fields to the Index Page Options page to control the display of Webmin and module updates.
 Moved settings related to Webmin's built-in webserver to the new Web Server Options page.
+The client-side expiry time for static files served by Webmin can now be configured on the Web Server Options page, and can be customized on a per-file basis.
index 12886db..815784a 100755 (executable)
@@ -16,6 +16,16 @@ else {
        $miniserv{'expires'} = $in{'expires'};
        }
 
+# Save per-path expires
+for(my $i=0; defined($p = $in{"expirespath_$i"}); $i++) {
+       $t = $in{"expirestime_$i"};
+       next if ($p !~ /\S/);
+       $t =~ /^\d+$/ || &error(&text('web_eexpires2', $i+1));
+       push(@expires_paths, [ $p, $t ]);
+       }
+$miniserv{'expires_paths'} = join("\t", map { $_->[0]."=".$_->[1] }
+                                           @expires_paths);
+
 # Save stack trace option
 $gconfig{'error_stack'} = $in{'stack'};
 
index 686fdc2..4842d6a 100755 (executable)
@@ -13,6 +13,26 @@ print &ui_table_row($text{'web_expires'},
        &ui_opt_textbox("expires", $miniserv{'expires'}, 10,
                        $text{'web_expiresdef'}, $text{'web_expiressecs'}));
 
+# Additonal expiry times based on path
+my @expires_paths;
+foreach my $pe (split(/\t+/, $miniserv{'expires_paths'})) {
+       my ($p, $e) = split(/=/, $pe);
+       if ($p && $e ne '') {
+               push(@expires_paths, [ $p, $e ]);
+               }
+       }
+push(@expires_paths, [ undef, $miniserv{'expires'} || 86400 ]);
+my $etable = &ui_columns_start([ $text{'web_expirespath'},
+                                $text{'web_expirestime'} ]);
+for(my $i=0; $i<@expires_paths; $i++) {
+       $etable .= &ui_columns_row([
+               &ui_textbox("expirespath_$i", $expires_paths[$i]->[0], 40),
+               &ui_textbox("expirestime_$i", $expires_paths[$i]->[1], 10),
+               ]);
+       }
+$etable .= &ui_columns_end();
+print &ui_table_row($text{'web_expirespaths'}, $etable);
+
 # Show call stack on error
 print &ui_table_row($text{'advanced_stack'},
                    &ui_yesno_radio("stack", int($gconfig{'error_stack'})));
index ffa03c2..81e0f9e 100644 (file)
@@ -936,6 +936,10 @@ web_expires=Client-side cache time for static files
 web_expiresdef=Webmin default (7 days)
 web_expiressecs=Time in seconds
 web_err=Failed to save web server options
-web_eexpires=Missing or non-numeric client size cache time
+web_eexpires=Missing or non-numeric client side cache time
+web_expirespaths=Client-side cache times based on URL path
+web_expirespath=Path regular expression
+web_expirestime=Cache time in seconds
+web_eexpires2=Missing or non-numeric client side cache time in row $1
 
 __norefs=1