diff --git a/CHANGELOG.md b/CHANGELOG.md index f1c2795dc4..a17eabcb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each AppEngine version, listed here to ease deployment and troubleshooting. ## Next Release (replace with git tag when deployed) + * Note: Reverted public `cache-control` headers except for `/documentation/` pages. ## `20251023t081900-all` * Bump runtimeVersion to `2025.10.22`. diff --git a/app/lib/frontend/handlers/cache_control.dart b/app/lib/frontend/handlers/cache_control.dart index 966dd6a14f..0c0ba9d1d8 100644 --- a/app/lib/frontend/handlers/cache_control.dart +++ b/app/lib/frontend/handlers/cache_control.dart @@ -62,20 +62,13 @@ final class CacheControl { public: true, ); - /// `Cache-Control` headers for package content pages, returning content that + /// `Cache-Control` headers for documentation pages, returning content that /// is not updated frequently. - static const packageContentPage = CacheControl( + static const documentationPage = CacheControl( maxAge: Duration(minutes: 30), public: true, ); - /// `Cache-Control` headers for package listing pages, returning content that - /// is may be updated frequently. - static const packageListingPage = CacheControl( - maxAge: Duration(minutes: 5), - public: true, - ); - /// `Cache-Control` headers for API end-points returning completion data for /// use in IDE integrations. static const completionData = CacheControl( diff --git a/app/lib/frontend/handlers/landing.dart b/app/lib/frontend/handlers/landing.dart index c2265e98e3..4b0da1e9d5 100644 --- a/app/lib/frontend/handlers/landing.dart +++ b/app/lib/frontend/handlers/landing.dart @@ -5,7 +5,6 @@ import 'dart:async'; import 'package:_pub_shared/search/tags.dart'; -import 'package:pub_dev/frontend/handlers/cache_control.dart'; import 'package:pub_dev/search/top_packages.dart'; import 'package:shelf/shelf.dart' as shelf; @@ -50,10 +49,7 @@ Future indexLandingHandler(shelf.Request request) async { } if (requestContext.uiCacheEnabled) { - return htmlResponse( - (await cache.uiIndexPage().get(_render))!, - headers: CacheControl.packageListingPage.headers, - ); + return htmlResponse((await cache.uiIndexPage().get(_render))!); } return htmlResponse(await _render()); } diff --git a/app/lib/frontend/handlers/listing.dart b/app/lib/frontend/handlers/listing.dart index f387d864c0..51a45c74e0 100644 --- a/app/lib/frontend/handlers/listing.dart +++ b/app/lib/frontend/handlers/listing.dart @@ -7,8 +7,6 @@ import 'dart:async'; import 'package:_pub_shared/search/search_form.dart'; import 'package:_pub_shared/search/tags.dart'; import 'package:logging/logging.dart'; -import 'package:pub_dev/frontend/handlers/cache_control.dart'; -import 'package:pub_dev/frontend/request_context.dart'; import 'package:shelf/shelf.dart' as shelf; import '../../package/name_tracker.dart'; @@ -96,9 +94,6 @@ Future _packagesHandlerHtmlCore(shelf.Request request) async { openSections: openSections, ), status: statusCode, - headers: statusCode == 200 && requestContext.uiCacheEnabled - ? CacheControl.packageListingPage.headers - : null, ); _searchOverallLatencyTracker.add(sw.elapsed); return result; diff --git a/app/lib/frontend/handlers/package.dart b/app/lib/frontend/handlers/package.dart index dc13e8615d..30c6f3e2e7 100644 --- a/app/lib/frontend/handlers/package.dart +++ b/app/lib/frontend/handlers/package.dart @@ -356,10 +356,7 @@ Future _handlePackagePage({ } _packageDoneLatencyTracker.add(sw.elapsed); } - return htmlResponse( - cachedPage, - headers: cacheEnabled ? CacheControl.packageContentPage.headers : null, - ); + return htmlResponse(cachedPage); } /// Returns the optionally lowercased version of [name], but only if there diff --git a/app/lib/task/handlers.dart b/app/lib/task/handlers.dart index 4252744bf3..2cee967c22 100644 --- a/app/lib/task/handlers.dart +++ b/app/lib/task/handlers.dart @@ -93,7 +93,7 @@ Future handleDartDoc( if (htmlBytes != null) { return htmlBytesResponse( htmlBytes, - headers: CacheControl.packageContentPage.headers, + headers: CacheControl.documentationPage.headers, ); } @@ -217,7 +217,7 @@ Future handleDartDoc( await htmlBytesCacheEntry.set(bytes!); return htmlBytesResponse( bytes, - headers: CacheControl.packageContentPage.headers, + headers: CacheControl.documentationPage.headers, ); case DocPageStatusCode.redirect: return redirectPathResponse(status.redirectPath!); @@ -243,14 +243,14 @@ Future handleDartDoc( } if (request.method.toUpperCase() == 'HEAD') { - return htmlResponse('', headers: CacheControl.packageContentPage.headers); + return htmlResponse('', headers: CacheControl.documentationPage.headers); } final acceptsGzip = request.acceptsGzipEncoding(); return shelf.Response.ok( acceptsGzip ? dataGz : gzip.decode(dataGz), headers: { - ...CacheControl.packageContentPage.headers, + ...CacheControl.documentationPage.headers, 'Content-Type': mime, 'Vary': 'Accept-Encoding', // body depends on accept-encoding! if (acceptsGzip) 'Content-Encoding': 'gzip', diff --git a/pkg/pub_integration/lib/src/fake_test_context_provider.dart b/pkg/pub_integration/lib/src/fake_test_context_provider.dart index 806738f35c..b3a8f49c63 100644 --- a/pkg/pub_integration/lib/src/fake_test_context_provider.dart +++ b/pkg/pub_integration/lib/src/fake_test_context_provider.dart @@ -58,20 +58,14 @@ class TestContextProvider { await _fakePubServerProcess.kill(); } - Future createAnonymousTestUser({ - bool expectAllResponsesToBeCacheControlPublic = true, - }) async { + Future createAnonymousTestUser() async { final session = await _testBrowser.createSession(); return TestUser( email: '', browserApi: PubApiClient(pubHostedUrl), serverApi: PubApiClient(pubHostedUrl), withBrowserPage: (Future Function(Page) fn) async { - return await session.withPage( - fn: fn, - expectAllResponsesToBeCacheControlPublic: - expectAllResponsesToBeCacheControlPublic, - ); + return await session.withPage(fn: fn); }, readLatestEmail: () async => throw UnimplementedError(), createCredentials: () async => throw UnimplementedError(), diff --git a/pkg/pub_integration/lib/src/test_browser.dart b/pkg/pub_integration/lib/src/test_browser.dart index ef73c5c37a..6d29b544db 100644 --- a/pkg/pub_integration/lib/src/test_browser.dart +++ b/pkg/pub_integration/lib/src/test_browser.dart @@ -185,10 +185,7 @@ class TestBrowserSession { TestBrowserSession(this._browser, this._context); /// Creates a new page and setup overrides and tracking. - Future withPage({ - required Future Function(Page page) fn, - bool expectAllResponsesToBeCacheControlPublic = false, - }) async { + Future withPage({required Future Function(Page page) fn}) async { final clientErrors = []; final serverErrors = []; final page = await _context.newPage(); @@ -278,9 +275,7 @@ class TestBrowserSession { } final shouldBePublic = - firstPathSegment == 'static' || - firstPathSegment == 'documentation' || - expectAllResponsesToBeCacheControlPublic; + firstPathSegment == 'static' || firstPathSegment == 'documentation'; final knownExemption = firstPathSegment == 'experimental' || firstPathSegment == 'report'; if (shouldBePublic && !knownExemption) { diff --git a/pkg/pub_integration/test/fake_sign_in_test.dart b/pkg/pub_integration/test/fake_sign_in_test.dart index 529b00f004..a994705bae 100644 --- a/pkg/pub_integration/test/fake_sign_in_test.dart +++ b/pkg/pub_integration/test/fake_sign_in_test.dart @@ -43,9 +43,7 @@ void main() { // This should normally be used as a test user in higher-level tests. // However, this integration test is to verify the lower-level details // of the fake sign-in, and the relation cookie and redirect handling. - final browserSession = await fakeTestScenario.createAnonymousTestUser( - expectAllResponsesToBeCacheControlPublic: false, - ); + final browserSession = await fakeTestScenario.createAnonymousTestUser(); String? firstSessionId; // sign-in page await browserSession.withBrowserPage((page) async {