-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathheaders.js
More file actions
76 lines (67 loc) · 1.91 KB
/
headers.js
File metadata and controls
76 lines (67 loc) · 1.91 KB
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
71
72
73
74
75
76
const concat = require('simple-concat')
const get = require('../')
const http = require('http')
const str = require('string-to-stream')
const test = require('tape')
const zlib = require('zlib')
test('custom headers', function (t) {
t.plan(2)
const server = http.createServer(function (req, res) {
t.equal(req.headers['custom-header'], 'custom-value')
res.statusCode = 200
res.end('response')
})
server.listen(0, function () {
const port = server.address().port
get({
href: 'http://localhost:' + port,
headers: {
'custom-header': 'custom-value'
}
}, function (err, res) {
t.error(err)
res.resume()
server.close()
})
})
})
test('gzip response', function (t) {
t.plan(4)
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.setHeader('content-encoding', 'gzip')
str('response').pipe(zlib.createGzip()).pipe(res)
})
server.listen(0, function () {
const port = server.address().port
get('http://localhost:' + port, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200) // statusCode still works on gunzip stream
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})
test('deflate response', function (t) {
t.plan(4)
const server = http.createServer(function (req, res) {
res.statusCode = 200
res.setHeader('content-encoding', 'deflate')
str('response').pipe(zlib.createDeflate()).pipe(res)
})
server.listen(0, function () {
const port = server.address().port
get('http://localhost:' + port, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200) // statusCode still works on inflate stream
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})