Changeset 3409
- Timestamp:
- 03/10/10 22:22:40 (2 years ago)
- Files:
-
- trunk/master/_bin/munin-cgi-graph.in (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/master/_bin/munin-cgi-graph.in
r3404 r3409 88 88 # If a "Cache-Control: no-cache" header gets send, we regenerate the image in every case: 89 89 my $no_cache = $pinpoint || defined($ENV{HTTP_CACHE_CONTROL}) && $ENV{HTTP_CACHE_CONTROL} =~ /no-cache/i; 90 print STDERR "no_cache:$no_cache\n";91 90 92 91 # Compute the cache values … … 102 101 print "Status: 304\n"; 103 102 print "Content-Type: image/png\n"; 103 print "Content-Length: 0\n"; 104 my $headers = get_headers_for_file($filename, $graph_ttl); 105 106 # Conditionaly add timing informations 107 print "Expires: $headers->{Expires}\n"; 108 print "Last-Modified: " . $headers->{"Last-Modified"} . "\n"; 109 104 110 print "\n"; 105 106 111 # We replied, continue with the next request 107 112 next; … … 118 123 } 119 124 120 # At this time the file exists and should be served121 my @stats = stat ($filename);122 my $mtime_epoch = $stats[9];123 my $last_modified = get_w3c_date_from_epoch($mtime_epoch);124 125 # "Expires" has to use last modified time as base:126 my $graph_next_expires = $mtime_epoch - ($mtime_epoch % $graph_ttl) + $graph_ttl;127 my $expires = get_w3c_date_from_epoch($graph_next_expires);128 125 129 126 … … 131 128 print "Status: 200\n"; 132 129 print "Content-Type: image/png\n"; 133 print "Content-Length: $stats[7]\n";134 135 # Conditionaly add timing informations 136 print "Expires: $expires\n" if $expires;137 print "Last-Modified: $last_modified\n" if $last_modified; 130 my $headers = get_headers_for_file($filename, $graph_ttl); 131 foreach my $header_name (keys %$headers) { 132 print "$header_name: $headers->{$header_name}\n"; 133 } 134 138 135 print "\n"; 139 136 … … 143 140 # END FAST-CGI LOOP 144 141 142 sub get_headers_for_file { 143 my $filename = shift; 144 my $graph_ttl = shift; 145 146 # At this time the file exists and should be served 147 my @stats = stat ($filename); 148 my $mtime_epoch = $stats[9]; 149 my $last_modified = get_w3c_date_from_epoch($mtime_epoch); 150 151 # "Expires" has to use last modified time as base: 152 my $graph_next_expires = $mtime_epoch - ($mtime_epoch % $graph_ttl) + $graph_ttl; 153 my $expires = get_w3c_date_from_epoch($graph_next_expires); 154 155 return { 156 "Expires" => $expires, 157 "Last-Modified" => $last_modified, 158 "Content-Length" => $stats[7], 159 }; 160 161 } 162 145 163 sub get_w3c_date_from_epoch { 146 164 my $epoch = shift; 147 print STDERR "get_w3c_date_from_epoch($epoch)\n";148 165 return strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime($epoch)); 149 166 } … … 274 291 my $logfile = shift; 275 292 293 # remove old file 294 unlink($filename) or die("cannot remove old graph file: $!"); 295 276 296 $serv =~ s{[^\w_\/"'\[\]\(\)+=-]}{_}g; $serv =~ /^(.+)$/; $serv = $1; #" 277 297 # . needs to be legal in host names
