Skip to content

Commit bbae239

Browse files
committed
Revert most cache-control headers from #9027 keeping for documentation pages.
1 parent aeb0f44 commit bbae239

File tree

9 files changed

+14
-45
lines changed

9 files changed

+14
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each
22
AppEngine version, listed here to ease deployment and troubleshooting.
33

44
## Next Release (replace with git tag when deployed)
5+
* Note: Reverted public `cache-control` headers except for `/documentation/` pages.
56

67
## `20251023t081900-all`
78
* Bump runtimeVersion to `2025.10.22`.

app/lib/frontend/handlers/cache_control.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,13 @@ final class CacheControl {
6262
public: true,
6363
);
6464

65-
/// `Cache-Control` headers for package content pages, returning content that
65+
/// `Cache-Control` headers for documentation pages, returning content that
6666
/// is not updated frequently.
67-
static const packageContentPage = CacheControl(
67+
static const documentationPage = CacheControl(
6868
maxAge: Duration(minutes: 30),
6969
public: true,
7070
);
7171

72-
/// `Cache-Control` headers for package listing pages, returning content that
73-
/// is may be updated frequently.
74-
static const packageListingPage = CacheControl(
75-
maxAge: Duration(minutes: 5),
76-
public: true,
77-
);
78-
7972
/// `Cache-Control` headers for API end-points returning completion data for
8073
/// use in IDE integrations.
8174
static const completionData = CacheControl(

app/lib/frontend/handlers/landing.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:async';
66

77
import 'package:_pub_shared/search/tags.dart';
8-
import 'package:pub_dev/frontend/handlers/cache_control.dart';
98
import 'package:pub_dev/search/top_packages.dart';
109
import 'package:shelf/shelf.dart' as shelf;
1110

@@ -50,10 +49,7 @@ Future<shelf.Response> indexLandingHandler(shelf.Request request) async {
5049
}
5150

5251
if (requestContext.uiCacheEnabled) {
53-
return htmlResponse(
54-
(await cache.uiIndexPage().get(_render))!,
55-
headers: CacheControl.packageListingPage.headers,
56-
);
52+
return htmlResponse((await cache.uiIndexPage().get(_render))!);
5753
}
5854
return htmlResponse(await _render());
5955
}

app/lib/frontend/handlers/listing.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'dart:async';
77
import 'package:_pub_shared/search/search_form.dart';
88
import 'package:_pub_shared/search/tags.dart';
99
import 'package:logging/logging.dart';
10-
import 'package:pub_dev/frontend/handlers/cache_control.dart';
11-
import 'package:pub_dev/frontend/request_context.dart';
1210
import 'package:shelf/shelf.dart' as shelf;
1311

1412
import '../../package/name_tracker.dart';
@@ -96,9 +94,6 @@ Future<shelf.Response> _packagesHandlerHtmlCore(shelf.Request request) async {
9694
openSections: openSections,
9795
),
9896
status: statusCode,
99-
headers: statusCode == 200 && requestContext.uiCacheEnabled
100-
? CacheControl.packageListingPage.headers
101-
: null,
10297
);
10398
_searchOverallLatencyTracker.add(sw.elapsed);
10499
return result;

app/lib/frontend/handlers/package.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,7 @@ Future<shelf.Response> _handlePackagePage({
356356
}
357357
_packageDoneLatencyTracker.add(sw.elapsed);
358358
}
359-
return htmlResponse(
360-
cachedPage,
361-
headers: cacheEnabled ? CacheControl.packageContentPage.headers : null,
362-
);
359+
return htmlResponse(cachedPage);
363360
}
364361

365362
/// Returns the optionally lowercased version of [name], but only if there

app/lib/task/handlers.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Future<shelf.Response> handleDartDoc(
9393
if (htmlBytes != null) {
9494
return htmlBytesResponse(
9595
htmlBytes,
96-
headers: CacheControl.packageContentPage.headers,
96+
headers: CacheControl.documentationPage.headers,
9797
);
9898
}
9999

@@ -217,7 +217,7 @@ Future<shelf.Response> handleDartDoc(
217217
await htmlBytesCacheEntry.set(bytes!);
218218
return htmlBytesResponse(
219219
bytes,
220-
headers: CacheControl.packageContentPage.headers,
220+
headers: CacheControl.documentationPage.headers,
221221
);
222222
case DocPageStatusCode.redirect:
223223
return redirectPathResponse(status.redirectPath!);
@@ -243,14 +243,14 @@ Future<shelf.Response> handleDartDoc(
243243
}
244244

245245
if (request.method.toUpperCase() == 'HEAD') {
246-
return htmlResponse('', headers: CacheControl.packageContentPage.headers);
246+
return htmlResponse('', headers: CacheControl.documentationPage.headers);
247247
}
248248

249249
final acceptsGzip = request.acceptsGzipEncoding();
250250
return shelf.Response.ok(
251251
acceptsGzip ? dataGz : gzip.decode(dataGz),
252252
headers: {
253-
...CacheControl.packageContentPage.headers,
253+
...CacheControl.documentationPage.headers,
254254
'Content-Type': mime,
255255
'Vary': 'Accept-Encoding', // body depends on accept-encoding!
256256
if (acceptsGzip) 'Content-Encoding': 'gzip',

pkg/pub_integration/lib/src/fake_test_context_provider.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,14 @@ class TestContextProvider {
5858
await _fakePubServerProcess.kill();
5959
}
6060

61-
Future<TestUser> createAnonymousTestUser({
62-
bool expectAllResponsesToBeCacheControlPublic = true,
63-
}) async {
61+
Future<TestUser> createAnonymousTestUser() async {
6462
final session = await _testBrowser.createSession();
6563
return TestUser(
6664
email: '',
6765
browserApi: PubApiClient(pubHostedUrl),
6866
serverApi: PubApiClient(pubHostedUrl),
6967
withBrowserPage: <T>(Future<T> Function(Page) fn) async {
70-
return await session.withPage<T>(
71-
fn: fn,
72-
expectAllResponsesToBeCacheControlPublic:
73-
expectAllResponsesToBeCacheControlPublic,
74-
);
68+
return await session.withPage<T>(fn: fn);
7569
},
7670
readLatestEmail: () async => throw UnimplementedError(),
7771
createCredentials: () async => throw UnimplementedError(),

pkg/pub_integration/lib/src/test_browser.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ class TestBrowserSession {
185185
TestBrowserSession(this._browser, this._context);
186186

187187
/// Creates a new page and setup overrides and tracking.
188-
Future<R> withPage<R>({
189-
required Future<R> Function(Page page) fn,
190-
bool expectAllResponsesToBeCacheControlPublic = false,
191-
}) async {
188+
Future<R> withPage<R>({required Future<R> Function(Page page) fn}) async {
192189
final clientErrors = <ClientError>[];
193190
final serverErrors = <String>[];
194191
final page = await _context.newPage();
@@ -278,9 +275,7 @@ class TestBrowserSession {
278275
}
279276

280277
final shouldBePublic =
281-
firstPathSegment == 'static' ||
282-
firstPathSegment == 'documentation' ||
283-
expectAllResponsesToBeCacheControlPublic;
278+
firstPathSegment == 'static' || firstPathSegment == 'documentation';
284279
final knownExemption =
285280
firstPathSegment == 'experimental' || firstPathSegment == 'report';
286281
if (shouldBePublic && !knownExemption) {

pkg/pub_integration/test/fake_sign_in_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ void main() {
4343
// This should normally be used as a test user in higher-level tests.
4444
// However, this integration test is to verify the lower-level details
4545
// of the fake sign-in, and the relation cookie and redirect handling.
46-
final browserSession = await fakeTestScenario.createAnonymousTestUser(
47-
expectAllResponsesToBeCacheControlPublic: false,
48-
);
46+
final browserSession = await fakeTestScenario.createAnonymousTestUser();
4947
String? firstSessionId;
5048
// sign-in page
5149
await browserSession.withBrowserPage((page) async {

0 commit comments

Comments
 (0)