Comparing version
Baucis Change Log | ||
================= | ||
v0.10.4 | ||
------- | ||
Fix a bug where Accept used "DEL" instead of "DELETE." Fix another bug where ETag was not sent for HEAD requests. | ||
v0.10.3 | ||
@@ -5,0 +9,0 @@ ------- |
// __Dependencies__ | ||
var url = require('url'); | ||
var eutils = require('express/lib/utils'); | ||
var mongoose = require('mongoose'); | ||
@@ -37,2 +38,4 @@ | ||
var location; | ||
var replacer; | ||
var spaces; | ||
var findBy = request.baucis.controller.get('findBy'); | ||
@@ -46,4 +49,9 @@ var basePath = request.originalUrl; | ||
if (request.baucis.noBody) { | ||
if (request.method === 'HEAD') return response.send(); | ||
else return response.send(204); | ||
if (request.method !== 'HEAD') return response.send(204); | ||
if (documents) { | ||
replacer = request.baucis.controller.get('json replacer'); | ||
spaces = request.baucis.controller.get('json spaces'); | ||
response.set('ETag', eutils.etag(JSON.stringify(documents, replacer, spaces))); | ||
} | ||
return response.send(200); | ||
} | ||
@@ -50,0 +58,0 @@ // If it's a document count (e.g. the result of a DELETE), send it back and |
@@ -36,21 +36,8 @@ // __Dependencies__ | ||
count: function (request, response, next) { | ||
var lastModifiedPath = request.baucis.controller.get('lastModified'); | ||
request.baucis.count = true; | ||
if (lastModifiedPath) { | ||
request.baucis.query.select('-_id ' + lastModifiedPath); | ||
request.baucis.query.exec(function (error, documents) { | ||
if (error) return next(error); | ||
request.baucis.documents = documents; | ||
next(); | ||
}); | ||
} | ||
else { | ||
request.baucis.query.count(function (error, count) { | ||
if (error) return next(error); | ||
request.baucis.documents = count; | ||
next(); | ||
}); | ||
} | ||
request.baucis.query.exec(function (error, documents) { | ||
if (error) return next(error); | ||
request.baucis.documents = documents; | ||
next(); | ||
}); | ||
}, | ||
@@ -57,0 +44,0 @@ update: function (request, response, next) { |
// __Dependencies__ | ||
var url = require('url'); | ||
var extend = require('util')._extend; | ||
var extend = require('util')._extend; // TODO use connect/util/merge (cutils) | ||
var qs = require('querystring'); | ||
@@ -58,2 +58,3 @@ | ||
var allowed = request.baucis.controller.activeVerbs().map(function (verb) { | ||
if (verb === 'del') return 'DELETE'; | ||
return verb.toUpperCase(); | ||
@@ -60,0 +61,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/wprl/baucis", | ||
"version": "0.10.3", | ||
"version": "0.10.4", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
baucis v0.10.3 | ||
baucis v0.10.4 | ||
============== | ||
@@ -3,0 +3,0 @@ |
@@ -709,3 +709,3 @@ var expect = require('expect.js'); | ||
expect(response).to.have.property('statusCode', 405); | ||
expect(response.headers).to.have.property('allow', 'HEAD,POST,PUT,DEL'); | ||
expect(response.headers).to.have.property('allow', 'HEAD,POST,PUT,DELETE'); | ||
done(); | ||
@@ -712,0 +712,0 @@ }); |
@@ -43,5 +43,17 @@ var expect = require('expect.js'); | ||
if (err) return done(err); | ||
var updatedModified = new Date(response.headers['last-modified']); | ||
var options = { | ||
url: 'http://localhost:8012/api/v1/vegetables/' + vege._id, | ||
json: true | ||
}; | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(new Date(response.headers['last-modified'])).to.be.greaterThan(originalModified); | ||
done(); | ||
expect(updatedModified).to.be.greaterThan(originalModified); | ||
request.head(options, function (err, response, body) { | ||
if (err) return done(err); | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(new Date(response.headers['last-modified'])).to.eql(updatedModified); | ||
done(); | ||
}); | ||
}); | ||
@@ -51,6 +63,16 @@ }, 1000); | ||
it('should set allowed', function (done) { | ||
var options = { | ||
url: 'http://localhost:8012/api/v1/vegetables', | ||
json: true | ||
}; | ||
request.head(options, function (err, response, body) { | ||
if (err) return done(err); | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(response.headers).to.have.property('allow', 'HEAD,GET,POST,PUT,DELETE'); | ||
done(); | ||
}); | ||
}); | ||
it('should set ETag', function (done) { | ||
var latestModifiedDate = Math.max.apply(null, vegetables.map(function (vege) { | ||
return vege.get('lastModified'); | ||
})); | ||
var options = { | ||
@@ -62,5 +84,12 @@ url: 'http://localhost:8012/api/v1/vegetables', | ||
if (err) return done(err); | ||
var etag = response.headers['etag']; | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(response.headers).to.have.property('etag'); | ||
done(); | ||
request.head(options, function (err, response, body) { | ||
if (err) return done(err); | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(response.headers).to.have.property('etag', etag); | ||
done(); | ||
}); | ||
}); | ||
@@ -67,0 +96,0 @@ }); |
621443
0.19%3760
0.62%