a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/api] Ask the browser to cache media redirects

Kopper 87216408 252a6386

+29 -7
+29 -7
Iceshrimp.Backend/Controllers/Web/DriveController.cs
··· 32 32 HttpClient httpClient 33 33 ) : ControllerBase 34 34 { 35 - private const string CacheControl = "max-age=31536000, immutable"; 35 + private const string ImmutableCacheControl = "max-age=31536000, immutable"; 36 + private const string TemporaryCacheControl = "max-age=3600"; 36 37 37 38 [EnableCors("drive")] 38 39 [EnableRateLimiting("proxy")] ··· 55 56 ?? throw GracefulException.NotFound("Emoji not found"); 56 57 57 58 if (!options.Value.ProxyRemoteMedia || emoji.Host == null) 59 + { 60 + Response.Headers.CacheControl = TemporaryCacheControl; 58 61 return Redirect(emoji.RawPublicUrl); 62 + } 59 63 60 64 return await ProxyAsync(emoji.RawPublicUrl, null, null); 61 65 } ··· 71 75 ?? throw GracefulException.NotFound("Instance not found"); 72 76 73 77 if (instance.FaviconUrl == null) 78 + { 79 + Response.Headers.CacheControl = TemporaryCacheControl; 74 80 return NoContent(); 81 + } 75 82 76 83 if (!options.Value.ProxyRemoteMedia) 84 + { 85 + Response.Headers.CacheControl = TemporaryCacheControl; 77 86 return Redirect(instance.FaviconUrl); 87 + } 78 88 79 89 return await ProxyAsync(instance.FaviconUrl, null, null); 80 90 } ··· 92 102 if (user.Avatar is null) 93 103 { 94 104 var stream = await IdenticonHelper.GetIdenticonAsync(user.Id); 95 - Response.Headers.CacheControl = CacheControl; 105 + Response.Headers.CacheControl = ImmutableCacheControl; 96 106 return new InlineFileStreamResult(stream, "image/png", $"{user.Id}.png", false); 97 107 } 98 108 99 109 if (!options.Value.ProxyRemoteMedia) 110 + { 111 + Response.Headers.CacheControl = TemporaryCacheControl; 100 112 return Redirect(user.Avatar.RawThumbnailAccessUrl); 113 + } 101 114 102 115 return await GetFileByAccessKey(user.Avatar.AccessKey, "thumbnail", user.Avatar); 103 116 } ··· 113 126 ?? throw GracefulException.NotFound("User not found"); 114 127 115 128 if (user.Banner is null) 129 + { 130 + Response.Headers.CacheControl = TemporaryCacheControl; 116 131 return NoContent(); 132 + } 117 133 118 134 if (!options.Value.ProxyRemoteMedia) 135 + { 136 + Response.Headers.CacheControl = TemporaryCacheControl; 119 137 return Redirect(user.Banner.RawThumbnailAccessUrl); 138 + } 120 139 121 140 return await GetFileByAccessKey(user.Banner.AccessKey, "thumbnail", user.Banner); 122 141 } ··· 130 149 public async Task<IActionResult> GetIdenticonByUserId(string userId) 131 150 { 132 151 var stream = await IdenticonHelper.GetIdenticonAsync(userId); 133 - Response.Headers.CacheControl = CacheControl; 152 + Response.Headers.CacheControl = ImmutableCacheControl; 134 153 return new InlineFileStreamResult(stream, "image/png", $"{userId}.png", false); 135 154 } 136 155 ··· 523 542 || p.ThumbnailAccessKey == accessKey); 524 543 if (file == null) 525 544 { 526 - Response.Headers.CacheControl = "max-age=86400"; 545 + Response.Headers.CacheControl = TemporaryCacheControl; 527 546 throw GracefulException.NotFound("File not found"); 528 547 } 529 548 ··· 534 553 : file.RawAccessUrl; 535 554 536 555 if (!options.Value.ProxyRemoteMedia) 556 + { 557 + Response.Headers.CacheControl = TemporaryCacheControl; 537 558 return Redirect(fetchUrl); 559 + } 538 560 539 561 try 540 562 { ··· 562 584 var path = Path.Join(pathBase, accessKey); 563 585 var stream = System.IO.File.OpenRead(path); 564 586 565 - Response.Headers.CacheControl = CacheControl; 587 + Response.Headers.CacheControl = ImmutableCacheControl; 566 588 Response.Headers.XContentTypeOptions = "nosniff"; 567 589 568 590 return Constants.BrowserSafeMimeTypes.Contains(file.Type) ··· 578 600 throw GracefulException.NotFound("File not found"); 579 601 } 580 602 581 - Response.Headers.CacheControl = CacheControl; 603 + Response.Headers.CacheControl = ImmutableCacheControl; 582 604 Response.Headers.XContentTypeOptions = "nosniff"; 583 605 584 606 return Constants.BrowserSafeMimeTypes.Contains(file.Type) ··· 601 623 throw GracefulException.BadGateway("Failed to proxy request: content type mismatch", suppressLog: true); 602 624 // @formatter:on 603 625 604 - Response.Headers.CacheControl = CacheControl; 626 + Response.Headers.CacheControl = ImmutableCacheControl; 605 627 Response.Headers.XContentTypeOptions = "nosniff"; 606 628 607 629 var stream = await res.Content.ReadAsStreamAsync();