Skip to content

Commit

Permalink
HEAD updates
Browse files Browse the repository at this point in the history
For #102.
  • Loading branch information
mnot committed Oct 17, 2020
1 parent c0ad544 commit c6ab33d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/templates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
108 changes: 108 additions & 0 deletions tests/updateHead.mjs
Original file line number Diff line number Diff line change
@@ -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']
]
}
]
}
]
}

0 comments on commit c6ab33d

Please sign in to comment.