Skip to content

Commit f2e7330

Browse files
jnarebJunio C Hamano
authored andcommitted
gitweb: blobs defined by non-textual hash ids can be cached
Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 17848fc commit f2e7330

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

gitweb/gitweb.perl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,12 @@ sub git_heads {
23632363
}
23642364

23652365
sub git_blob_plain {
2366+
# blobs defined by non-textual hash id's can be cached
2367+
my $expires;
2368+
if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2369+
$expires = "+1d";
2370+
}
2371+
23662372
if (!defined $hash) {
23672373
if (defined $file_name) {
23682374
my $base = $hash_base || git_get_head_hash($project);
@@ -2386,8 +2392,10 @@ sub git_blob_plain {
23862392
$save_as .= '.txt';
23872393
}
23882394

2389-
print $cgi->header(-type => "$type",
2390-
-content_disposition => "inline; filename=\"$save_as\"");
2395+
print $cgi->header(
2396+
-type => "$type",
2397+
-expires=>$expires,
2398+
-content_disposition => "inline; filename=\"$save_as\"");
23912399
undef $/;
23922400
binmode STDOUT, ':raw';
23932401
print <$fd>;
@@ -2397,6 +2405,12 @@ sub git_blob_plain {
23972405
}
23982406

23992407
sub git_blob {
2408+
# blobs defined by non-textual hash id's can be cached
2409+
my $expires;
2410+
if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2411+
$expires = "+1d";
2412+
}
2413+
24002414
if (!defined $hash) {
24012415
if (defined $file_name) {
24022416
my $base = $hash_base || git_get_head_hash($project);
@@ -2414,7 +2428,7 @@ sub git_blob {
24142428
close $fd;
24152429
return git_blob_plain($mimetype);
24162430
}
2417-
git_header_html();
2431+
git_header_html(undef, $expires);
24182432
my $formats_nav = '';
24192433
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
24202434
if (defined $file_name) {

0 commit comments

Comments
 (0)