parent
5d642af8c3
commit
c762b16f62
@ -4,6 +4,7 @@ unreleased
|
||||
* Add `options` argument to `req.range`
|
||||
- Includes the `combine` option
|
||||
* Fix Windows absolute path check using forward slashes
|
||||
* Improve error with invalid arguments to `req.get()`
|
||||
* Improve performance for `res.json`/`res.jsonp` in most cases
|
||||
* deps: accepts@~1.3.3
|
||||
- Fix including type extensions in parameters in `Accept` parsing
|
||||
|
@ -57,6 +57,14 @@ var req = exports = module.exports = {
|
||||
|
||||
req.get =
|
||||
req.header = function header(name) {
|
||||
if (!name) {
|
||||
throw new TypeError('name argument is required to req.get');
|
||||
}
|
||||
|
||||
if (typeof name !== 'string') {
|
||||
throw new TypeError('name must be a string to req.get');
|
||||
}
|
||||
|
||||
var lc = name.toLowerCase();
|
||||
|
||||
switch (lc) {
|
||||
|
@ -31,5 +31,29 @@ describe('req', function(){
|
||||
.set('Referrer', 'http://foobar.com')
|
||||
.expect('http://foobar.com', done);
|
||||
})
|
||||
|
||||
it('should throw missing header name', function (done) {
|
||||
var app = express()
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.end(req.get())
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(500, /TypeError: name argument is required to req.get/, done)
|
||||
})
|
||||
|
||||
it('should throw for non-string header name', function (done) {
|
||||
var app = express()
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.end(req.get(42))
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(500, /TypeError: name must be a string to req.get/, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user