-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
/
Copy pathreq.fresh.js
70 lines (56 loc) · 1.63 KB
/
req.fresh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
var express = require('../')
, request = require('supertest');
describe('req', function(){
describe('.fresh', function(){
it('should return true when the resource is not modified', function(done){
var app = express();
var etag = '"12345"';
app.use(function(req, res){
res.set('ETag', etag);
res.send(req.fresh);
});
request(app)
.get('/')
.set('If-None-Match', etag)
.expect(304, done);
})
it('should return false when the resource is modified', function(done){
var app = express();
app.use(function(req, res){
res.set('ETag', '"123"');
res.send(req.fresh);
});
request(app)
.get('/')
.set('If-None-Match', '"12345"')
.expect(200, 'false', done);
})
it('should return false without response headers', function(done){
var app = express();
app.disable('x-powered-by')
app.use(function(req, res){
res.send(req.fresh);
});
request(app)
.get('/')
.expect(200, 'false', done);
})
it('should ignore "If-Modified-Since" when "If-None-Match" is present', function(done) {
var app = express();
const etag = '"FooBar"'
const now = Date.now()
app.disable('x-powered-by')
app.use(function(req, res) {
res.set('Etag', etag)
res.set('Last-Modified', new Date(now).toUTCString())
res.send(req.fresh);
});
request(app)
.get('/')
.set('If-Modified-Since', new Date(now - 1000).toUTCString)
.set('If-None-Match', etag)
.expect(304, done);
})
})
})