U6: IndexHtmlInjector (markers OFFERINGS-JSON-LD / OFFERINGS-HTML), 60s cache, invalidatie bij wijziging, ETag
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -148,6 +148,32 @@ public static class StaticContentExtensions
|
||||
}
|
||||
|
||||
context.Response.ContentType = "text/html; charset=utf-8";
|
||||
|
||||
// Modules fill marker comments in index.html (e.g. the current offerings); cached, with an ETag.
|
||||
var injector = context.RequestServices.GetService<IndexHtmlInjector>();
|
||||
var page = injector is null
|
||||
? null
|
||||
: await injector.GetAsync(websiteIndex, context.Request, context.RequestAborted);
|
||||
if (page is not null)
|
||||
{
|
||||
context.Response.Headers["Cache-Control"] = "no-cache";
|
||||
context.Response.Headers["ETag"] = page.ETag;
|
||||
if (context.Response.StatusCode == StatusCodes.Status200OK
|
||||
&& context.Request.Headers.IfNoneMatch.Contains(page.ETag))
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status304NotModified;
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.ContentLength = page.Body.Length;
|
||||
if (!HttpMethods.IsHead(context.Request.Method))
|
||||
{
|
||||
await context.Response.Body.WriteAsync(page.Body, context.RequestAborted);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await context.Response.SendFileAsync(websiteIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user