fix(places): make no-store the default and refuse an unreadable Places 200

Every Google route now sets no-store right after the same-site gate and
switches to private, max-age=300 only on a confirmed answer, so the
proxy's own 400, 405, 429 and 502 replies are no longer left without a
header. Both Places routes answer an unreadable 200 body with 502 instead
of caching an empty result, as the geocode routes already did. The test
pins the allowlist with OVER_DAILY_LIMIT and UNKNOWN_ERROR and covers the
unreadable and empty Places bodies; the changelog fragment is shorter.
This commit is contained in:
German Khokhlov committed 2026-11-19 18:29:24 +04:00
1 parent f22701ae70
commit 31b6b25d8b
4 files changed
+103 -35

No files matched your search

+58 -1
View File
@@ -209,7 +209,12 @@ test('a refused Places or Geocoding answer is not kept by the browser', async (t
t.mock.method(globalThis, 'fetch', async () =>
Response.json({ status, results: [] }),
);
for (const denied of ['REQUEST_DENIED', 'OVER_QUERY_LIMIT']) {
for (const denied of [
'REQUEST_DENIED',
'OVER_QUERY_LIMIT',
'OVER_DAILY_LIMIT',
'UNKNOWN_ERROR',
]) {
status = denied;
const answer = await request('/api/google/geocode', '?address=Austin');
assert.equal(answer.statusCode, 200);
@@ -223,6 +228,58 @@ test('a refused Places or Geocoding answer is not kept by the browser', async (t
}
});
const ROUTES = [
['/api/google/nearby-places', '?lat=30&lon=-97'],
['/api/google/text-search', '?q=museum&lat=30&lon=-97'],
];
const truncated = () =>
new Response(
new ReadableStream({
start(c) {
c.enqueue(new TextEncoder().encode('{"places":[{"displayName"'));
c.error(new TypeError('terminated'));
},
}),
{ status: 200 },
);
for (const [name, body] of [
['non-JSON', () => new Response('<html>not json</html>', { status: 200 })],
['cut mid-body', truncated],
]) {
test(`an unreadable Places 200 (${name}) is a failure, not a cached empty answer`, async () => {
const request = install((middlewares) =>
googlePlacesContextProxy({
resolveApiKey: () => 'fixture-server-key',
fetchImpl: async () => body(),
}).configureServer({ middlewares }),
);
for (const [route, query] of ROUTES) {
const res = await request(route, query);
assert.equal(res.statusCode, 502, route);
assert.equal(res.headers['cache-control'], 'no-store', route);
assert.deepEqual(res.body.places, [], route);
assert.ok(res.body.error, route);
}
});
}
test('a real empty Places answer ({}) stays cacheable', async () => {
const request = install((middlewares) =>
googlePlacesContextProxy({
resolveApiKey: () => 'fixture-server-key',
fetchImpl: async () => Response.json({}),
}).configureServer({ middlewares }),
);
for (const [route, query] of ROUTES) {
const res = await request(route, query);
assert.equal(res.statusCode, 200, route);
assert.equal(res.headers['cache-control'], 'private, max-age=300', route);
assert.equal(res.body.error, null, route);
}
});
test('OSRM routing preserves aliases, cache, span guards and upstream failure behavior', async (t) => {
const request = install(installRouteMiddleware);
let calls = 0;