Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

more careful about when we say a resource is modified #836

Merged
merged 1 commit into from

3 participants

@drewfish
Owner

No description provided.

@caridy
Owner

+1

@drewfish drewfish merged commit c296bdd into yahoo:develop

1 check failed

Details default The Travis build is in progress
@add0n

I can confirm that this fixed the problem I was seeing - thanks Drew and Caridy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
21 lib/app/middleware/mojito-handler-static.js
@@ -48,11 +48,13 @@ function modified(req, headers) {
var modifiedSince = req.headers['if-modified-since'],
lastModified = headers['Last-Modified'],
noneMatch = req.headers['if-none-match'],
- etag = headers.ETag;
+ etag = headers.ETag,
+ etagModified = true,
+ dateModified = true;
// Check If-None-Match
if (noneMatch && etag && noneMatch === etag) {
- return false;
+ etagModified = false;
}
// Check If-Modified-Since
@@ -62,12 +64,12 @@ function modified(req, headers) {
// Ignore invalid dates
if (!isNaN(modifiedSince.getTime())) {
if (lastModified <= modifiedSince) {
- return false;
+ dateModified = false;
}
}
}
- return true;
+ return etagModified || dateModified;
}
/*
@@ -400,3 +402,14 @@ function staticProvider(store, logger, Y) {
module.exports = function (config) {
return staticProvider(config.store, config.logger, config.Y);
};
+
+
+// These will let us unit test
+module.exports._etag = etag;
+module.exports._forbidden = forbidden;
+module.exports._makeContentTypeHeader = makeContentTypeHeader;
+module.exports._modified = modified;
+module.exports._notFound = notFound;
+module.exports._notModified = notModified;
+
+
View
94 tests/unit/lib/app/middleware/test-handler-static.js
@@ -642,6 +642,100 @@ YUI().use('mojito-test-extra', 'test', function(Y) {
});
store.getResourceContent = realGetResourceContent;
+ },
+
+
+ 'test modified()': function() {
+ var reqHeaders, resHeaders, mod;
+ A.isFunction(factory._modified);
+
+ // 1. date same
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 123
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(false, mod, 'date same');
+
+ // 2. date req is older
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:01:52 GMT',
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 123
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(true, mod, 'date req is older');
+
+ // 3. date req is newer
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:09:52 GMT',
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 123
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(false, mod, 'date req is newer');
+
+ // 4. date invalid
+ reqHeaders = {
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 123
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(true, mod, 'date invalid');
+
+ // 5. etag same (yes duplicated)
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 123
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(false, mod, 'etag same (yes duplicated)');
+
+ // 6. etag different
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'if-none-match': 123
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 321
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(true, mod, 'etag different');
+
+ // 7. etag invalid
+ reqHeaders = {
+ 'if-modified-since': 'Fri, 30 Nov 2012 21:07:52 GMT'
+ };
+ resHeaders = {
+ 'Last-Modified': 'Fri, 30 Nov 2012 21:07:52 GMT',
+ 'ETag': 321
+ };
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(true, mod, 'etag invalid');
+
+ // 8. degenerate
+ reqHeaders = {};
+ resHeaders = {};
+ mod = factory._modified({headers: reqHeaders}, resHeaders);
+ A.areSame(true, mod, 'degenerate');
}
};
Something went wrong with that request. Please try again.