Skip to content

Commit

Permalink
Remove deprecated maxage method
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Dec 13, 2022
1 parent 0b7bd4b commit 66722bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
1.x
===

* Remove `send.maxage()` -- use `maxAge` in `options`

0.17.2 / 2021-12-11
===================

Expand Down
19 changes: 0 additions & 19 deletions index.js
Expand Up @@ -237,25 +237,6 @@ SendStream.prototype.from = deprecate.function(SendStream.prototype.root,
SendStream.prototype.root = deprecate.function(SendStream.prototype.root,
'send.root: pass root as option')

/**
* Set max-age to `maxAge`.
*
* @param {Number} maxAge
* @return {SendStream}
* @api public
*/

SendStream.prototype.maxage = deprecate.function(function maxage (maxAge) {
this._maxage = typeof maxAge === 'string'
? ms(maxAge)
: Number(maxAge)
this._maxage = !isNaN(this._maxage)
? Math.min(Math.max(0, this._maxage), MAX_MAXAGE)
: 0
debug('max-age %d', this._maxage)
return this
}, 'send.maxage: pass maxAge as option')

/**
* Emit error with `status`.
*
Expand Down
50 changes: 0 additions & 50 deletions test/send.js
Expand Up @@ -853,56 +853,6 @@ describe('send(file).pipe(res)', function () {
})
})

describe('.maxage()', function () {
it('should default to 0', function (done) {
var app = http.createServer(function (req, res) {
send(req, 'test/fixtures/name.txt')
.maxage(undefined)
.pipe(res)
})

request(app)
.get('/name.txt')
.expect('Cache-Control', 'public, max-age=0', done)
})

it('should floor to integer', function (done) {
var app = http.createServer(function (req, res) {
send(req, 'test/fixtures/name.txt')
.maxage(1234)
.pipe(res)
})

request(app)
.get('/name.txt')
.expect('Cache-Control', 'public, max-age=1', done)
})

it('should accept string', function (done) {
var app = http.createServer(function (req, res) {
send(req, 'test/fixtures/name.txt')
.maxage('30d')
.pipe(res)
})

request(app)
.get('/name.txt')
.expect('Cache-Control', 'public, max-age=2592000', done)
})

it('should max at 1 year', function (done) {
var app = http.createServer(function (req, res) {
send(req, 'test/fixtures/name.txt')
.maxage(Infinity)
.pipe(res)
})

request(app)
.get('/name.txt')
.expect('Cache-Control', 'public, max-age=31536000', done)
})
})

describe('.root()', function () {
it('should set root', function (done) {
var app = http.createServer(function (req, res) {
Expand Down

0 comments on commit 66722bd

Please sign in to comment.