Skip to content

Commit b0a70af

Browse files
committed
Rename x-rsf-cache-control to x-sw-cache-control.
1 parent 7a4c0e8 commit b0a70af

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

service-worker/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ workbox.routing.registerRoute(matchRuntimePath, async context => {
357357
// 2. it provide that to client and server build as a webpack define
358358
// 3. we should monkey-patch xhr to send x-rsf-api-version as a request header on all requests
359359

360-
if (apiRes.headers.get('x-rsf-cache-control')) {
360+
if (apiRes.headers.get('x-sw-cache-control')) {
361361
const path = url.pathname
362362

363363
caches.open(cacheName).then(cache => {

src/utils/withCaching.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* handler calls `e.preventDefault()`.
44
*
55
* @param {Function} handler The original event handle supplied to the component
6-
* @param {Function} defaultHandler A handler to run unless `e.preventDefault()` was called.
6+
* @param {Number} maxAgeSeconds The time in seconds that a result should be kept in the service worker cache.
77
* @return {Function}
88
*/
9-
export default function withCaching(handler, { browser, edge }) {
9+
export default function withCaching(handler, maxAgeSeconds) {
1010
return (req, res) => {
11-
if (browser.maxAgeSeconds) {
12-
res.setHeader('x-rsf-cache-control', `max-age: ${browser.maxAgeSeconds}`)
11+
if (maxAgeSeconds) {
12+
res.setHeader('x-sw-cache-control', `max-age: ${maxAgeSeconds}`)
1313
}
1414

1515
return handler(req, res)

test/utils/withCaching.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import withCaching from 'react-storefront/utils/withCaching'
22

33
describe('withCaching', () => {
4-
it('should set header if maxAgeSeconds are present on the browser', () => {
4+
it('should set header if maxAgeSeconds is present', () => {
55
const res = { setHeader: jest.fn() }
66

7-
withCaching(jest.fn(), { browser: { maxAgeSeconds: 10 } })({}, res)
7+
withCaching(jest.fn(), 10)({}, res)
88

99
expect(res.setHeader).toBeCalled()
1010
})
1111

12-
it('should not set header if maxAgeSeconds are not present on the browser', () => {
12+
it('should not set header if maxAgeSeconds are not present', () => {
1313
const res = { setHeader: jest.fn() }
1414

15-
withCaching(jest.fn(), { browser: {} })({}, res)
15+
withCaching(jest.fn())({}, res)
1616

1717
expect(res.setHeader).not.toBeCalled()
1818
})

0 commit comments

Comments
 (0)