Properly support all HTTP methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
unreleased
|
||||
==========
|
||||
|
||||
* Properly support all HTTP methods
|
||||
* Support vanilla node.js http servers
|
||||
|
||||
1.0.3 / 2014-05-20
|
||||
|
||||
@@ -85,7 +85,12 @@ exports = module.exports = function serveIndex(root, options){
|
||||
, stylesheet = options.stylesheet || defaultStylesheet;
|
||||
|
||||
return function serveIndex(req, res, next) {
|
||||
if ('GET' != req.method && 'HEAD' != req.method) return next();
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
var status = 'OPTIONS' === req.method ? 200 : 405;
|
||||
res.writeHead(status, {'Allow': 'GET, HEAD, OPTIONS'});
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
var url = parse(req.url)
|
||||
, dir = decodeURIComponent(url.pathname)
|
||||
|
||||
@@ -9,6 +9,43 @@ describe('serveIndex(root)', function () {
|
||||
serveIndex.should.throw(/root path required/)
|
||||
})
|
||||
|
||||
it('should serve a directory index', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.get('/')
|
||||
.set('Accept', 'text/html, */*;q=0.5')
|
||||
.expect(200, /todo\.txt/, done)
|
||||
})
|
||||
|
||||
it('should work with HEAD requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.head('/')
|
||||
.set('Accept', 'text/html, */*;q=0.5')
|
||||
.expect(200, '', done)
|
||||
})
|
||||
|
||||
it('should work with OPTIONS requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.options('/')
|
||||
.set('Accept', 'text/html, */*;q=0.5')
|
||||
.expect('Allow', 'GET, HEAD, OPTIONS')
|
||||
.expect(200, done)
|
||||
})
|
||||
|
||||
it('should deny POST requests', function (done) {
|
||||
var server = createServer()
|
||||
|
||||
request(server)
|
||||
.post('/')
|
||||
.set('Accept', 'text/html, */*;q=0.5')
|
||||
.expect(405, done)
|
||||
})
|
||||
|
||||
describe('when given Accept: header', function () {
|
||||
describe('when Accept: application/json is given', function () {
|
||||
it('should respond with json', function (done) {
|
||||
|
||||
Reference in New Issue
Block a user