Skip to content

Commit

Permalink
Merge e9ff7d9 into 336cedf
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 3, 2022
2 parents 336cedf + e9ff7d9 commit dd32009
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 245 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
strategy:
matrix:
name:
- Node.js 0.8
- Node.js 0.10
- Node.js 0.12
- io.js 1.x
Expand All @@ -32,11 +31,6 @@ jobs:
- Node.js 17.x

include:
- name: Node.js 0.8
node-version: "0.8"
npm-i: mocha@2.5.3 supertest@1.1.0
npm-rm: nyc

- name: Node.js 0.10
node-version: "0.10"
npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0
Expand Down Expand Up @@ -114,21 +108,11 @@ jobs:
shell: bash -eo pipefail -l {0}
run: |
nvm install --default ${{ matrix.node-version }}
if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
nvm install --alias=npm 0.10
nvm use ${{ matrix.node-version }}
sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")"
npm config set strict-ssl false
fi
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
- name: Configure npm
run: npm config set shrinkwrap false

- name: Remove npm module(s) ${{ matrix.npm-rm }}
run: npm rm --silent --save-dev ${{ matrix.npm-rm }}
if: matrix.npm-rm != ''

- name: Install npm module(s) ${{ matrix.npm-i }}
run: npm install --save-dev ${{ matrix.npm-i }}
if: matrix.npm-i != ''
Expand Down
10 changes: 10 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
1.x
===

* Drop support for Node.js 0.8
* Remove `from` alias to `root` -- use `root` directly
* Remove `send.etag()` -- use `etag` in `options`
* Remove `send.index()` -- use `index` in `options`
* Remove `send.maxage()` -- use `maxAge` in `options`
* Remove `send.root()` -- use `root` in `options`

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

Expand Down
91 changes: 2 additions & 89 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ function SendStream (req, path, options) {
this._root = opts.root
? resolve(opts.root)
: null

if (!this._root && opts.from) {
this.from(opts.from)
}
}

/**
Expand All @@ -172,20 +168,6 @@ function SendStream (req, path, options) {

util.inherits(SendStream, Stream)

/**
* Enable or disable etag generation.
*
* @param {Boolean} val
* @return {SendStream}
* @api public
*/

SendStream.prototype.etag = deprecate.function(function etag (val) {
this._etag = Boolean(val)
debug('etag %s', this._etag)
return this
}, 'send.etag: pass etag as option')

/**
* Enable or disable "hidden" (dot) files.
*
Expand All @@ -201,61 +183,6 @@ SendStream.prototype.hidden = deprecate.function(function hidden (val) {
return this
}, 'send.hidden: use dotfiles option')

/**
* Set index `paths`, set to a falsy
* value to disable index support.
*
* @param {String|Boolean|Array} paths
* @return {SendStream}
* @api public
*/

SendStream.prototype.index = deprecate.function(function index (paths) {
var index = !paths ? [] : normalizeList(paths, 'paths argument')
debug('index %o', paths)
this._index = index
return this
}, 'send.index: pass index as option')

/**
* Set root `path`.
*
* @param {String} path
* @return {SendStream}
* @api public
*/

SendStream.prototype.root = function root (path) {
this._root = resolve(String(path))
debug('root %s', this._root)
return this
}

SendStream.prototype.from = deprecate.function(SendStream.prototype.root,
'send.from: pass root as option')

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 Expand Up @@ -612,7 +539,7 @@ SendStream.prototype.send = function send (path, stat) {
var ranges = req.headers.range
var offset = options.start || 0

if (headersSent(res)) {
if (res.headersSent) {
// impossible to send now
this.headersAlreadySent()
return
Expand Down Expand Up @@ -1009,7 +936,7 @@ function getHeaderNames (res) {
/**
* Determine if emitter has listeners of a given type.
*
* The way to do this check is done three different ways in Node.js >= 0.8
* The way to do this check is done three different ways in Node.js >= 0.10
* so this consolidates them into a minimal set using instance methods.
*
* @param {EventEmitter} emitter
Expand All @@ -1026,20 +953,6 @@ function hasListeners (emitter, type) {
return count > 0
}

/**
* Determine if the response headers have been sent.
*
* @param {object} res
* @returns {boolean}
* @private
*/

function headersSent (res) {
return typeof res.headersSent !== 'boolean'
? Boolean(res._header)
: res.headersSent
}

/**
* Normalize the index option into an array.
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"index.js"
],
"engines": {
"node": ">= 0.8.0"
"node": ">= 0.10"
},
"scripts": {
"lint": "eslint .",
Expand Down
139 changes: 0 additions & 139 deletions test/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,35 +772,6 @@ describe('send(file).pipe(res)', function () {
})
})

describe('.etag()', function () {
it('should support disabling etags', function (done) {
var app = http.createServer(function (req, res) {
send(req, req.url, { root: fixtures })
.etag(false)
.pipe(res)
})

request(app)
.get('/name.txt')
.expect(shouldNotHaveHeader('ETag'))
.expect(200, done)
})
})

describe('.from()', function () {
it('should set with deprecated from', function (done) {
var app = http.createServer(function (req, res) {
send(req, req.url)
.from(fixtures)
.pipe(res)
})

request(app)
.get('/pets/../name.txt')
.expect(200, 'tobi', done)
})
})

describe('.hidden()', function () {
it('should default support sending hidden files', function (done) {
var app = http.createServer(function (req, res) {
Expand All @@ -814,108 +785,6 @@ describe('send(file).pipe(res)', function () {
.expect(200, 'secret', done)
})
})

describe('.index()', function () {
it('should be configurable', function (done) {
var app = http.createServer(function (req, res) {
send(req, req.url, { root: fixtures })
.index('tobi.html')
.pipe(res)
})

request(app)
.get('/')
.expect(200, '<p>tobi</p>', done)
})

it('should support disabling', function (done) {
var app = http.createServer(function (req, res) {
send(req, req.url, { root: fixtures })
.index(false)
.pipe(res)
})

request(app)
.get('/pets/')
.expect(403, done)
})

it('should support fallbacks', function (done) {
var app = http.createServer(function (req, res) {
send(req, req.url, { root: fixtures })
.index(['default.htm', 'index.html'])
.pipe(res)
})

request(app)
.get('/pets/')
.expect(200, fs.readFileSync(path.join(fixtures, 'pets', 'index.html'), 'utf8'), done)
})
})

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) {
send(req, req.url)
.root(fixtures)
.pipe(res)
})

request(app)
.get('/pets/../name.txt')
.expect(200, 'tobi', done)
})
})
})

describe('send(file, options)', function () {
Expand Down Expand Up @@ -1027,14 +896,6 @@ describe('send(file, options)', function () {
})
})

describe('from', function () {
it('should set with deprecated from', function (done) {
request(createServer({ from: fixtures }))
.get('/pets/../name.txt')
.expect(200, 'tobi', done)
})
})

describe('dotfiles', function () {
it('should default to "ignore"', function (done) {
request(createServer({ root: fixtures }))
Expand Down

0 comments on commit dd32009

Please sign in to comment.