-
-
Notifications
You must be signed in to change notification settings - Fork 17.1k
/
Copy pathapp.head.js
66 lines (55 loc) · 1.37 KB
/
app.head.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
'use strict'
var express = require('../');
var request = require('supertest');
var assert = require('assert');
describe('HEAD', function(){
it('should default to GET', function(done){
var app = express();
app.get('/tobi', function(req, res){
// send() detects HEAD
res.send('tobi');
});
request(app)
.head('/tobi')
.expect(200, done);
})
it('should output the same headers as GET requests', function(done){
var app = express();
app.get('/tobi', function(req, res){
// send() detects HEAD
res.send('tobi');
});
request(app)
.head('/tobi')
.expect(200, function(err, res){
if (err) return done(err);
var headers = res.headers;
request(app)
.get('/tobi')
.expect(200, function(err, res){
if (err) return done(err);
delete headers.date;
delete res.headers.date;
assert.deepEqual(res.headers, headers);
done();
});
});
})
})
describe('app.head()', function(){
it('should override', function(done){
var app = express()
app.head('/tobi', function(req, res){
res.header('x-method', 'head')
res.end()
});
app.get('/tobi', function(req, res){
res.header('x-method', 'get')
res.send('tobi');
});
request(app)
.head('/tobi')
.expect('x-method', 'head')
.expect(200, done)
})
})