Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
11 changes: 2 additions & 9 deletions app/lib/frontend/handlers/cache_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions app/lib/frontend/handlers/landing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,10 +49,7 @@ Future<shelf.Response> 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());
}
5 changes: 0 additions & 5 deletions app/lib/frontend/handlers/listing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -96,9 +94,6 @@ Future<shelf.Response> _packagesHandlerHtmlCore(shelf.Request request) async {
openSections: openSections,
),
status: statusCode,
headers: statusCode == 200 && requestContext.uiCacheEnabled
? CacheControl.packageListingPage.headers
: null,
);
_searchOverallLatencyTracker.add(sw.elapsed);
return result;
Expand Down
5 changes: 1 addition & 4 deletions app/lib/frontend/handlers/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,7 @@ Future<shelf.Response> _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
Expand Down
8 changes: 4 additions & 4 deletions app/lib/task/handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Future<shelf.Response> handleDartDoc(
if (htmlBytes != null) {
return htmlBytesResponse(
htmlBytes,
headers: CacheControl.packageContentPage.headers,
headers: CacheControl.documentationPage.headers,
);
}

Expand Down Expand Up @@ -217,7 +217,7 @@ Future<shelf.Response> handleDartDoc(
await htmlBytesCacheEntry.set(bytes!);
return htmlBytesResponse(
bytes,
headers: CacheControl.packageContentPage.headers,
headers: CacheControl.documentationPage.headers,
);
case DocPageStatusCode.redirect:
return redirectPathResponse(status.redirectPath!);
Expand All @@ -243,14 +243,14 @@ Future<shelf.Response> 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',
Expand Down
10 changes: 2 additions & 8 deletions pkg/pub_integration/lib/src/fake_test_context_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,14 @@ class TestContextProvider {
await _fakePubServerProcess.kill();
}

Future<TestUser> createAnonymousTestUser({
bool expectAllResponsesToBeCacheControlPublic = true,
}) async {
Future<TestUser> createAnonymousTestUser() async {
final session = await _testBrowser.createSession();
return TestUser(
email: '',
browserApi: PubApiClient(pubHostedUrl),
serverApi: PubApiClient(pubHostedUrl),
withBrowserPage: <T>(Future<T> Function(Page) fn) async {
return await session.withPage<T>(
fn: fn,
expectAllResponsesToBeCacheControlPublic:
expectAllResponsesToBeCacheControlPublic,
);
return await session.withPage<T>(fn: fn);
},
readLatestEmail: () async => throw UnimplementedError(),
createCredentials: () async => throw UnimplementedError(),
Expand Down
9 changes: 2 additions & 7 deletions pkg/pub_integration/lib/src/test_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ class TestBrowserSession {
TestBrowserSession(this._browser, this._context);

/// Creates a new page and setup overrides and tracking.
Future<R> withPage<R>({
required Future<R> Function(Page page) fn,
bool expectAllResponsesToBeCacheControlPublic = false,
}) async {
Future<R> withPage<R>({required Future<R> Function(Page page) fn}) async {
final clientErrors = <ClientError>[];
final serverErrors = <String>[];
final page = await _context.newPage();
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/pub_integration/test/fake_sign_in_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down