var assert = require('assert')
var http = require('http')
var doNotCache = require('./')
var receivedResponse = false
http.createServer()
.on('request', function (request, response) {
doNotCache(response)
response.end()
})
.listen(0 /* random high port */, function () {
var server = this
var port = server.address().port
http.request({port: port})
.on('response', function (response) {
var headers = response.headers
receivedResponse = true
// RFC 1945 (HTTP 1.0)
assert(headers['pragma'] === 'no-cache') // Section 10.12
assert(headers['expires'] === '0') // 10.7
// RFC 2616 (HTTP 1.1)
assert(
headers['cache-control']
.includes('no-cache')
) // Section 14.9.1
assert(
headers['cache-control']
.includes('no-store')
) // 14.9.2
assert(
headers['cache-control']
.includes('must-revalidate')
) // 14.9.4
server.close()
})
.end()
})
process.on('exit', function () {
assert(receivedResponse === true)
})
-
Notifications
You must be signed in to change notification settings - Fork 0
set HTTP response headers to prevent caching
License
kemitchell/do-not-cache.js
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
set HTTP response headers to prevent caching
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published