Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
statiCache no longer tries to handle range requests, typos, hit uses …
…date header for freshness
- Loading branch information
Showing
2 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var connect = require('../') | ||
, assert = require('assert') | ||
, should = require('should') | ||
, http = require('http') | ||
, create = require('./common').create; | ||
|
||
/** | ||
* Path to ./test/fixtures/ | ||
*/ | ||
|
||
var fixturesPath = __dirname + '/fixtures'; | ||
|
||
var app = create( | ||
connect.staticCache(), | ||
connect.static(fixturesPath, { maxAge: 60000 }) | ||
); | ||
|
||
var app2 = create( | ||
connect.staticCache(), | ||
connect.static(fixturesPath, { maxAge: 0 }) | ||
); | ||
|
||
|
||
module.exports = { | ||
|
||
'unconditional request': function() { | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'ifnonematch request': function() { | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('etag'); | ||
assert.response( | ||
app, | ||
{ | ||
url: '/user.json', | ||
headers: { | ||
"If-None-Match": res.headers.etag | ||
} | ||
}, | ||
function(res) { | ||
res.statusCode.should.equal(304); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'old if-none-match request': function() { | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('etag'); | ||
assert.response( | ||
app, | ||
{ url: '/user.json', | ||
headers: { | ||
'If-None-Match': 'foobar' | ||
} | ||
}, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'if-modified since request': function() { | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('last-modified'); | ||
assert.response( | ||
app, | ||
{ | ||
url: '/user.json', | ||
headers: { | ||
'If-Modified-Since': res.headers['last-modified'] | ||
} | ||
}, | ||
function(res) { | ||
res.statusCode.should.equal(304); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'old if-modified-since request': function() { | ||
assert.response( | ||
app2, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
assert.response( | ||
app2, | ||
{ | ||
url: '/user.json', | ||
headers: { | ||
'If-Modified-Since': 'Sat, 29 Oct 1994 19:43:31 GMT' | ||
} | ||
}, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'no-cache request': function() { | ||
assert.response( | ||
app, | ||
{ url: '/user.json' }, | ||
function(res) { | ||
res.statusCode.should.equal(200); | ||
res.headers.should.have.property('etag'); | ||
assert.response( | ||
app, | ||
{ | ||
url: '/user.json', | ||
headers: { | ||
'Cache-Control': 'no-cache, max-age=0', | ||
'If-None-Match': res.headers.etag | ||
} | ||
}, | ||
function(res) { | ||
res.statusCode.should.equal(304); | ||
res.headers.should.have.property('date'); | ||
res.headers.should.have.property('last-modified'); | ||
res.headers.should.have.property('etag'); | ||
} | ||
); | ||
} | ||
); | ||
}, | ||
|
||
'test range request': function(){ | ||
assert.response(app, | ||
{ url: '/list' }, | ||
function(res) { | ||
assert.response(app, | ||
{ url: '/list', headers: { Range: 'bytes=3-6' }}, | ||
{ body: '4567', 'Content-Range': 'bytes 3-6/9', status: 206 }); | ||
}); | ||
} | ||
}; |