Skip to content

Align HttpSys caching with ResponseCaching checks #69671

Agent suggestions

Public preview

Description

@BrennanConroy

ResponseCaching checks values like no-store and no-cache when deciding whether a response should be cached.

var responseCacheControlHeader = context.HttpContext.Response.Headers.CacheControl;
// Only cache pages explicitly marked with public
if (!HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.PublicString))
{
context.Logger.ResponseWithoutPublicNotCacheable();
return false;
}
// Check response no-store
if (HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.NoStoreString))
{
context.Logger.ResponseWithNoStoreNotCacheable();
return false;
}
// Check no-cache
if (HeaderUtilities.ContainsCacheDirective(responseCacheControlHeader, CacheControlHeaderValue.NoCacheString))
{
context.Logger.ResponseWithNoCacheNotCacheable();
return false;
}

HttpSys currently relies on public, we should update the checks here to avoid any mistakes that could come from user error adding both public and a non-caching primitive.

// We require 'public' and 's-max-age' or 'max-age' or the Expires header.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-httpsys

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions