Skip to content

Commit

Permalink
Do not alter headers in forwarding scenarios
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Marbach <daniel.marbach@openplace.net>
  • Loading branch information
mauroservienti and danielmarbach committed Feb 2, 2024
1 parent e2dee3a commit 8f9e562
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Expand Up @@ -6,6 +6,12 @@ class CachingHttpHandler : IResultFilter
{
public void OnResultExecuting(ResultExecutingContext context)
{
if (context.HttpContext.Response.HasStarted)
{
// In forwarding scenarios we don't want to alter headers set by other instances
return;
}

// TODO do we even need to do this
var response = context.HttpContext.Response;
if (!response.Headers.ContainsKey("Cache-Control"))
Expand Down
Expand Up @@ -17,6 +17,12 @@ class NotModifiedStatusHttpHandler : IResultFilter

public void OnResultExecuting(ResultExecutingContext context)
{
if (context.HttpContext.Response.HasStarted)
{
// In forwarding scenarios we don't want to alter headers set by other instances
return;
}

var statusCode = context.HttpContext.Response.StatusCode;
if (statusCode is < 200 or > 299)
{
Expand Down
Expand Up @@ -27,6 +27,11 @@ static string GetFileVersion()
static readonly string FileVersion;
public void OnResultExecuting(ResultExecutingContext context)
{
if (context.HttpContext.Response.HasStarted)
{
// In forwarding scenarios we don't want to alter headers set by other instances
return;
}
context.HttpContext.Response.Headers["X-Particular-Version"] = FileVersion;
}

Expand Down

0 comments on commit 8f9e562

Please sign in to comment.