Treat ENAMETOOLONG as code 414
This commit is contained in:
@@ -4,6 +4,7 @@ unreleased
|
||||
* Fix content negotiation when no `Accept` header
|
||||
* Properly support all HTTP methods
|
||||
* Support vanilla node.js http servers
|
||||
* Treat `ENAMETOOLONG` as code 414
|
||||
|
||||
1.0.3 / 2014-05-20
|
||||
==================
|
||||
|
||||
@@ -109,9 +109,16 @@ exports = module.exports = function serveIndex(root, options){
|
||||
|
||||
// check if we have a directory
|
||||
fs.stat(path, function(err, stat){
|
||||
if (err) return 'ENOENT' == err.code
|
||||
? next()
|
||||
: next(err);
|
||||
if (err && err.code === 'ENOENT') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.status = err.code === 'ENAMETOOLONG'
|
||||
? 414
|
||||
: 500;
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!stat.isDirectory()) return next();
|
||||
|
||||
|
||||
+10
-1
@@ -75,6 +75,15 @@ describe('serveIndex(root)', function () {
|
||||
.expect(404, 'Not Found', done)
|
||||
})
|
||||
|
||||
it('should treat an ENAMETOOLONG as a 414', function (done) {
|
||||
var path = Array(11000).join('foobar')
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/' + path)
|
||||
.expect(414, done)
|
||||
})
|
||||
|
||||
it('should skip non-directories', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
@@ -373,7 +382,7 @@ function createServer(dir, opts) {
|
||||
return http.createServer(function (req, res) {
|
||||
_serveIndex(req, res, function (err) {
|
||||
res.statusCode = err ? (err.status || 500) : 404
|
||||
res.end(err ? err.mesage : 'Not Found')
|
||||
res.end(err ? err.message : 'Not Found')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user