From c6ab33d0b2ee51beacb97ec1cadacea7b4568d34 Mon Sep 17 00:00:00 2001 From: Mark Nottingham Date: Sat, 17 Oct 2020 17:42:00 +1100 Subject: [PATCH] HEAD updates For #102. --- lib/templates.mjs | 3 +- tests/index.mjs | 3 +- tests/updateHead.mjs | 108 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 tests/updateHead.mjs diff --git a/lib/templates.mjs b/lib/templates.mjs index 7e93131..995ebeb 100644 --- a/lib/templates.mjs +++ b/lib/templates.mjs @@ -22,7 +22,8 @@ export const stale = makeTemplate({ export const becomeStale = makeTemplate({ response_headers: [ - ['Cache-Control', 'max-age=2'] + ['Cache-Control', 'max-age=2'], + ['Template-A', '1'] ], setup: true, pause_after: true diff --git a/tests/index.mjs b/tests/index.mjs index 7f72fcb..dcba852 100644 --- a/tests/index.mjs +++ b/tests/index.mjs @@ -16,8 +16,9 @@ import conditionalLm from './conditional-lm.mjs' import conditionalEtag from './conditional-etag.mjs' import headers from './headers.mjs' import update304 from './update304.mjs' +import updateHead from './updateHead.mjs' import invalidation from './invalidation.mjs' import partial from './partial.mjs' import other from './other.mjs' -export default [ccFreshness, ccParse, ageParse, expires, expiresParse, ccResponse, stale, heuristic, methods, statuses, ccRequest, pragma, vary, varyParse, conditionalLm, conditionalEtag, headers, update304, invalidation, partial, other] +export default [ccFreshness, ccParse, ageParse, expires, expiresParse, ccResponse, stale, heuristic, methods, statuses, ccRequest, pragma, vary, varyParse, conditionalLm, conditionalEtag, headers, update304, updateHead, invalidation, partial, other] diff --git a/tests/updateHead.mjs b/tests/updateHead.mjs new file mode 100644 index 0000000..d8186e4 --- /dev/null +++ b/tests/updateHead.mjs @@ -0,0 +1,108 @@ + +import * as templates from '../lib/templates.mjs' + +export default + +{ + name: 'HEAD updates', + id: 'updateHEAD', + description: 'HTTP [specifies](https://httpwg.org/http-core/draft-ietf-httpbis-cache-latest.html#head.effects) that `HEAD` responses should update stored responses under certain conditions.', + tests: [ + { + name: 'Does HTTP cache write through a HEAD when stored response is stale?', + id: 'head-writethrough', + kind: 'check', + requests: [ + templates.becomeStale({}), + { + request_method: 'HEAD', + expected_method: 'HEAD' + } + ] + }, + { + name: 'Does HTTP cache preserve stored fields not received in a `200` response to a `HEAD`?', + id: 'head-200-retain', + kind: 'check', + depends_on: ['head-writethrough'], + requests: [ + templates.becomeStale({}), + { + request_method: 'HEAD', + expected_method: 'HEAD', + expected_response_headers: [ + ['Template-A', '1'] + ] + } + ] + }, + { + name: 'Does HTTP cache update freshness lifetime recieved in a `200` response to a `HEAD`?', + id: 'head-200-freshness-update', + kind: 'check', + depends_on: ['head-writethrough'], + requests: [ + templates.becomeStale({}), + { + request_method: 'HEAD', + expected_method: 'HEAD', + response_headers: [ + ['Cache-Control', 'max-age=1000'] + ], + }, + { + expected_type: 'cached' + } + ] + }, + { + name: 'Does HTTP cache update stored fields recieved in a `200` response to a `HEAD`?', + id: 'head-200-update', + kind: 'check', + depends_on: ['head-writethrough', 'head-200-freshness-update'], + requests: [ + templates.becomeStale({}), + { + request_method: 'HEAD', + expected_method: 'HEAD', + response_headers: [ + ['Template-A', '2'], + ['Cache-Control', 'max-age=1000'] + ], + }, + { + expected_type: 'cached', + setup_tests: ['expected_type'], + expected_response_headers: [ + ['Template-A', '2'] + ] + } + ] + }, + { + name: 'Does HTTP cache update stored fields recieved in a `410` response to a `HEAD`?', + id: 'head-410-update', + kind: 'check', + depends_on: ['head-writethrough', 'head-200-freshness-update'], + requests: [ + templates.becomeStale({}), + { + request_method: 'HEAD', + expected_method: 'HEAD', + response_status: [410, 'Gone'], + response_headers: [ + ['Template-A', '2'], + ['Cache-Control', 'max-age=1000'] + ], + }, + { + expected_type: 'cached', + setup_tests: ['expected_type'], + expected_response_headers: [ + ['Template-A', '2'] + ] + } + ] + } + ] +}