st 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +13 -0
- package/README.md +36 -22
- package/bin/server.js +95 -60
- package/package.json +12 -10
- package/st.js +504 -445
- package/test/basic.js +57 -49
- package/test/cli/basic-test.js +32 -0
- package/test/cli/common.js +108 -0
- package/test/cli/host-test.js +92 -0
- package/test/common.js +42 -30
- package/test/cors.js +11 -13
- package/test/dot-common.js +25 -19
- package/test/dot-false.js +6 -8
- package/test/dot-true.js +8 -8
- package/test/gzip-after-no-gzip.js +12 -19
- package/test/middleware.js +8 -14
- package/test/multi-mount.js +100 -83
- package/test/no-cache.js +8 -10
- package/test/no-cors.js +4 -5
- package/test/no-gzip-accepted-no-cache.js +18 -25
- package/test/no-gzip-accepted.js +18 -24
- package/test/no-gzip.js +4 -9
- package/test/parent-path.js +1 -1
- package/test/passthrough.js +36 -42
- package/test/preset-cache-control.js +31 -27
- package/.npmignore +0 -1
|
@@ -2,18 +2,12 @@ global.options = {
|
|
|
2
2
|
cachedHeader: true // inspect to see if something is served from cache
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var stExpect = common.stExpect
|
|
9
|
-
|
|
10
|
-
var test = require('tap').test
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
test('does not gzip first response', function(t) {
|
|
14
|
-
req('/test/st.js', {'accept-encoding':'none'},
|
|
15
|
-
function (er, res, body) {
|
|
5
|
+
const zlib = require('zlib')
|
|
6
|
+
const { req, stExpect } = require('./common.js')
|
|
7
|
+
const { test } = require('tap')
|
|
16
8
|
|
|
9
|
+
test('does not gzip first response', (t) => {
|
|
10
|
+
req('/test/st.js', { 'accept-encoding': 'none' }, (er, res, body) => {
|
|
17
11
|
t.equal(res.statusCode, 200)
|
|
18
12
|
t.notOk(res.headers['content-encoding'])
|
|
19
13
|
t.notOk(res.headers['x-from-cache'])
|
|
@@ -22,12 +16,9 @@ test('does not gzip first response', function(t) {
|
|
|
22
16
|
})
|
|
23
17
|
})
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function (er, res, body) {
|
|
29
|
-
|
|
30
|
-
t.ifError(er, 'no error')
|
|
19
|
+
test('gzips second response', (t) => {
|
|
20
|
+
req('/test/st.js', { 'accept-encoding': 'gzip' }, (er, res, body) => {
|
|
21
|
+
t.error(er, 'no error')
|
|
31
22
|
|
|
32
23
|
t.equal(res.statusCode, 200)
|
|
33
24
|
t.equal(res.headers['content-encoding'], 'gzip')
|
|
@@ -36,8 +27,10 @@ test('gzips second response', function (t) {
|
|
|
36
27
|
t.ok(body, 'returned a body')
|
|
37
28
|
t.notEqual(body.toString(), stExpect, 'gzipped string')
|
|
38
29
|
|
|
39
|
-
zlib.gunzip(body,
|
|
40
|
-
if (er)
|
|
30
|
+
zlib.gunzip(body, (er, body) => {
|
|
31
|
+
if (er) {
|
|
32
|
+
throw er
|
|
33
|
+
}
|
|
41
34
|
t.equal(body.toString(), stExpect)
|
|
42
35
|
t.end()
|
|
43
36
|
})
|
package/test/middleware.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var util = require('util')
|
|
5
|
-
var path = require('path')
|
|
1
|
+
const st = require('../st.js')
|
|
2
|
+
const { test } = require('tap')
|
|
3
|
+
const path = require('path')
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
const opts = Object.assign({
|
|
8
6
|
autoindex: true,
|
|
9
7
|
path: path.dirname(__dirname),
|
|
10
8
|
url: '/test'
|
|
11
9
|
}, global.options || {})
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
const mount = st(opts)
|
|
14
12
|
|
|
15
|
-
test('call next() if asset not found',
|
|
16
|
-
|
|
17
|
-
var res = {}
|
|
13
|
+
test('call next() if asset not found', (t) => {
|
|
14
|
+
const req = { url: '/does-not-exist?a=b' }
|
|
18
15
|
t.plan(1)
|
|
19
|
-
|
|
20
|
-
t.equal(req.url, '/does-not-exist?a=b')
|
|
21
|
-
}
|
|
22
|
-
mount(req, req, next)
|
|
16
|
+
mount(req, req, () => t.equal(req.url, '/does-not-exist?a=b'))
|
|
23
17
|
})
|
package/test/multi-mount.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const st = require('../st.js')
|
|
2
|
+
const test = require('tap').test
|
|
3
|
+
const port = process.env.PORT || 1337
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const request = require('request')
|
|
6
|
+
const assert = require('assert')
|
|
7
|
+
const fs = require('fs')
|
|
8
|
+
const http = require('http')
|
|
9
|
+
|
|
10
|
+
let middlewareServer
|
|
11
|
+
let server
|
|
11
12
|
|
|
12
13
|
// mount the dirname on the /test url
|
|
13
|
-
|
|
14
|
+
const mount1 = st({
|
|
14
15
|
autoindex: true,
|
|
15
16
|
path: path.dirname(__dirname),
|
|
16
17
|
url: '/test',
|
|
@@ -22,7 +23,7 @@ var mount1 = st({
|
|
|
22
23
|
})
|
|
23
24
|
|
|
24
25
|
// mount the test dir on the /blerg url
|
|
25
|
-
|
|
26
|
+
const mount2 = st({
|
|
26
27
|
autoindex: true,
|
|
27
28
|
path: __dirname,
|
|
28
29
|
url: '/blerg',
|
|
@@ -34,36 +35,45 @@ var mount2 = st({
|
|
|
34
35
|
})
|
|
35
36
|
|
|
36
37
|
function req (url, headers, cb) {
|
|
37
|
-
if (typeof headers === 'function')
|
|
38
|
-
cb = headers
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
if (typeof headers === 'function') {
|
|
39
|
+
cb = headers
|
|
40
|
+
headers = {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let reqs = 0
|
|
44
|
+
let errState = null
|
|
45
|
+
let prev = null
|
|
46
|
+
|
|
47
|
+
request({
|
|
48
|
+
encoding: null,
|
|
49
|
+
url: `http://localhost:${port}${url}`,
|
|
50
|
+
headers: headers,
|
|
51
|
+
agentOptions: { maxSockets: 50 }
|
|
52
|
+
}, next)
|
|
53
|
+
request({
|
|
54
|
+
encoding: null,
|
|
55
|
+
url: `http://localhost:${(port + 1)}${url}`,
|
|
56
|
+
headers: headers,
|
|
57
|
+
agentOptions: { maxSockets: 50 }
|
|
58
|
+
}, next)
|
|
52
59
|
|
|
53
60
|
function next (er, res, body) {
|
|
54
|
-
if (errState)
|
|
61
|
+
if (errState) {
|
|
55
62
|
return
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
}
|
|
64
|
+
if (er) {
|
|
65
|
+
errState = er
|
|
66
|
+
return cb(er, res, body)
|
|
67
|
+
}
|
|
58
68
|
if (++reqs === 2) {
|
|
59
|
-
assert.
|
|
69
|
+
assert.strictEqual(res.statusCode, prev.res.statusCode)
|
|
60
70
|
// compare dates, they should be approximately the same
|
|
61
71
|
assert(Math.abs(new Date(res.headers.date).getTime() -
|
|
62
72
|
new Date(res.headers.date).getTime()) < 1000)
|
|
63
73
|
// compare the headers minus the 'date' value
|
|
64
74
|
res.headers.date = prev.res.headers.date = null
|
|
65
|
-
assert.
|
|
66
|
-
assert.
|
|
75
|
+
assert.deepStrictEqual(res.headers, prev.res.headers)
|
|
76
|
+
assert.strictEqual(`${body}`, `${prev.body}`)
|
|
67
77
|
return cb(er, res, body)
|
|
68
78
|
}
|
|
69
79
|
prev = { res: res, body: body }
|
|
@@ -76,7 +86,7 @@ test('setup middleware server', function (t) {
|
|
|
76
86
|
mount1(req, res, function () {
|
|
77
87
|
mount2(req, res, function () {
|
|
78
88
|
res.statusCode = 404
|
|
79
|
-
return res.end(
|
|
89
|
+
return res.end(`Not a match: ${req.url}`)
|
|
80
90
|
})
|
|
81
91
|
})
|
|
82
92
|
})
|
|
@@ -90,7 +100,7 @@ test('setup regular server', function (t) {
|
|
|
90
100
|
server = http.createServer(function (req, res) {
|
|
91
101
|
if (!mount1(req, res) && !mount2(req, res)) {
|
|
92
102
|
res.statusCode = 404
|
|
93
|
-
return res.end(
|
|
103
|
+
return res.end(`Not a match: ${req.url}`)
|
|
94
104
|
}
|
|
95
105
|
})
|
|
96
106
|
server.listen(port + 1, '127.0.0.1', function () {
|
|
@@ -99,9 +109,9 @@ test('setup regular server', function (t) {
|
|
|
99
109
|
})
|
|
100
110
|
})
|
|
101
111
|
|
|
112
|
+
let stEtag
|
|
113
|
+
const stExpect = fs.readFileSync(require.resolve('../st.js')).toString()
|
|
102
114
|
|
|
103
|
-
var stEtag
|
|
104
|
-
var stExpect = fs.readFileSync(require.resolve('../st.js')).toString()
|
|
105
115
|
test('/test/st.js', function (t) {
|
|
106
116
|
req('/test/st.js', function (er, res, body) {
|
|
107
117
|
t.equal(res.statusCode, 200)
|
|
@@ -113,15 +123,15 @@ test('/test/st.js', function (t) {
|
|
|
113
123
|
})
|
|
114
124
|
|
|
115
125
|
test('/test/st.js 304', function (t) {
|
|
116
|
-
req('/test/st.js', {'if-none-match':stEtag}, function (er, res, body) {
|
|
126
|
+
req('/test/st.js', { 'if-none-match': stEtag }, function (er, res, body) {
|
|
117
127
|
t.equal(res.statusCode, 304)
|
|
118
128
|
t.equal(body.length, 0)
|
|
119
129
|
t.end()
|
|
120
130
|
})
|
|
121
131
|
})
|
|
122
132
|
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
let mmEtag
|
|
134
|
+
const mmExpect = fs.readFileSync(__filename, 'utf8')
|
|
125
135
|
test('/blerg/multi-mount.js', function (t) {
|
|
126
136
|
req('/blerg/multi-mount.js', function (er, res, body) {
|
|
127
137
|
t.equal(res.statusCode, 200)
|
|
@@ -141,93 +151,100 @@ test('/test/test/multi-mount.js', function (t) {
|
|
|
141
151
|
})
|
|
142
152
|
})
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var n = 3
|
|
154
|
+
let rmEtag
|
|
155
|
+
const rmExpect = fs.readFileSync(path.resolve(__dirname, '../README.md'), 'utf8')
|
|
156
|
+
let pjEtag
|
|
157
|
+
const pjExpect = fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')
|
|
158
|
+
let idEtag
|
|
159
|
+
const idExpect = fs.readFileSync(path.join(__dirname, '/fixtures/index.html'), 'utf8')
|
|
160
|
+
test('just get a few more etags', function (t) {
|
|
161
|
+
let n = 3
|
|
153
162
|
|
|
154
163
|
req('/test/package.json', function (er, res, body) {
|
|
155
|
-
if (er)
|
|
164
|
+
if (er) {
|
|
156
165
|
throw er
|
|
166
|
+
}
|
|
157
167
|
t.equal(body.toString(), pjExpect)
|
|
158
168
|
pjEtag = res.headers.etag
|
|
159
|
-
if (--n === 0)
|
|
169
|
+
if (--n === 0) {
|
|
160
170
|
t.end()
|
|
171
|
+
}
|
|
161
172
|
})
|
|
162
173
|
|
|
163
174
|
req('/test/README.md', function (er, res, body) {
|
|
164
|
-
if (er)
|
|
175
|
+
if (er) {
|
|
165
176
|
throw er
|
|
177
|
+
}
|
|
166
178
|
t.equal(body.toString(), rmExpect)
|
|
167
179
|
rmEtag = res.headers.etag
|
|
168
|
-
if (--n === 0)
|
|
180
|
+
if (--n === 0) {
|
|
169
181
|
t.end()
|
|
182
|
+
}
|
|
170
183
|
})
|
|
171
184
|
|
|
172
185
|
req('/test/test/fixtures/index.html', function (er, res, body) {
|
|
173
|
-
if (er)
|
|
186
|
+
if (er) {
|
|
174
187
|
throw er
|
|
188
|
+
}
|
|
175
189
|
t.equal(body.toString(), idExpect)
|
|
176
190
|
idEtag = res.headers.etag
|
|
177
|
-
if (--n === 0)
|
|
191
|
+
if (--n === 0) {
|
|
178
192
|
t.end()
|
|
193
|
+
}
|
|
179
194
|
})
|
|
180
195
|
})
|
|
181
196
|
|
|
182
197
|
test('many parallel requests', function (t) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
[
|
|
198
|
+
const n = 50
|
|
199
|
+
const reqs =
|
|
200
|
+
[['/test/test/multi-mount.js', mmEtag, mmExpect],
|
|
186
201
|
['/blerg/multi-mount.js', mmEtag, mmExpect],
|
|
187
202
|
['/test/st.js', stEtag, stExpect],
|
|
188
203
|
['/test/README.md', rmEtag, rmExpect],
|
|
189
204
|
['/test/package.json', pjEtag, pjExpect],
|
|
190
205
|
['/test/test/fixtures/index.html', idEtag, idExpect],
|
|
191
|
-
['/blerg/fixtures/index.html', idEtag, idExpect]
|
|
206
|
+
['/blerg/fixtures/index.html', idEtag, idExpect]]
|
|
192
207
|
|
|
193
|
-
|
|
208
|
+
let total = n * reqs.length
|
|
194
209
|
|
|
195
|
-
for (
|
|
210
|
+
for (let i = 0; i < n; i++) {
|
|
196
211
|
reqs.forEach(function (r) {
|
|
197
212
|
req(r[0], next(r))
|
|
198
213
|
})
|
|
199
214
|
}
|
|
200
215
|
|
|
201
|
-
function next (r) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
216
|
+
function next (r) {
|
|
217
|
+
return (er, res, body) => {
|
|
218
|
+
if (er) {
|
|
219
|
+
console.error('problem with', r[0])
|
|
220
|
+
throw er
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
t.pass(r[0])
|
|
224
|
+
t.ok(res)
|
|
225
|
+
t.ok(res.headers)
|
|
226
|
+
t.equal(res.headers.etag, r[1])
|
|
227
|
+
t.equal(body.toString(), r[2].toString())
|
|
228
|
+
|
|
229
|
+
if (--total === 0) {
|
|
230
|
+
process.nextTick(() => {
|
|
231
|
+
t.ok(require('fd')._totalOpenFds <= 6) // max of 3 fds per mount
|
|
232
|
+
t.end()
|
|
233
|
+
})
|
|
234
|
+
}
|
|
205
235
|
}
|
|
206
|
-
|
|
207
|
-
t.pass(r[0])
|
|
208
|
-
t.ok(res)
|
|
209
|
-
t.ok(res.headers)
|
|
210
|
-
t.equal(res.headers.etag, r[1])
|
|
211
|
-
t.equal(body.toString(), r[2].toString())
|
|
212
|
-
|
|
213
|
-
if (--total === 0) {
|
|
214
|
-
process.nextTick(function () {
|
|
215
|
-
t.ok(require('fd')._totalOpenFds <= 6) // max of 3 fds per mount
|
|
216
|
-
t.end()
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
}}
|
|
236
|
+
}
|
|
220
237
|
})
|
|
221
238
|
|
|
222
|
-
test('shutdown regular server',
|
|
223
|
-
server.close(
|
|
239
|
+
test('shutdown regular server', (t) => {
|
|
240
|
+
server.close(() => {
|
|
224
241
|
t.pass('closed')
|
|
225
242
|
t.end()
|
|
226
243
|
})
|
|
227
244
|
})
|
|
228
245
|
|
|
229
|
-
test('shutdown middleware server',
|
|
230
|
-
middlewareServer.close(
|
|
246
|
+
test('shutdown middleware server', (t) => {
|
|
247
|
+
middlewareServer.close(() => {
|
|
231
248
|
t.pass('closed')
|
|
232
249
|
t.end()
|
|
233
250
|
})
|
package/test/no-cache.js
CHANGED
|
@@ -4,18 +4,16 @@ global.options = {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// otherwise just the same as basic.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var mount = basic.mount
|
|
7
|
+
const { mount } = require('./basic.js')
|
|
8
|
+
const { test } = require('tap')
|
|
10
9
|
|
|
11
10
|
// additional tests to ensure that it's actually not caching.
|
|
12
|
-
var test = require('tap').test
|
|
13
11
|
|
|
14
|
-
test('all caches should be empty',
|
|
15
|
-
t.same(mount._this.cache.fd._cache.dump(),
|
|
16
|
-
t.same(mount._this.cache.stat._cache.dump(),
|
|
17
|
-
t.same(mount._this.cache.index._cache.dump(),
|
|
18
|
-
t.same(mount._this.cache.readdir._cache.dump(),
|
|
19
|
-
t.same(mount._this.cache.content._cache.dump(),
|
|
12
|
+
test('all caches should be empty', (t) => {
|
|
13
|
+
t.same(mount._this.cache.fd._cache.dump(), [])
|
|
14
|
+
t.same(mount._this.cache.stat._cache.dump(), [])
|
|
15
|
+
t.same(mount._this.cache.index._cache.dump(), [])
|
|
16
|
+
t.same(mount._this.cache.readdir._cache.dump(), [])
|
|
17
|
+
t.same(mount._this.cache.content._cache.dump(), [])
|
|
20
18
|
t.end()
|
|
21
19
|
})
|
package/test/no-cors.js
CHANGED
|
@@ -2,14 +2,13 @@ global.options = {
|
|
|
2
2
|
cors: false
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var test = require('tap').test
|
|
8
|
-
var req = common.req
|
|
5
|
+
const { req } = require('./common')
|
|
6
|
+
const test = require('tap').test
|
|
9
7
|
|
|
10
8
|
test('without CORS headers', function (t) {
|
|
11
9
|
req('/test/st.js', function (er, res) {
|
|
10
|
+
t.error(er)
|
|
12
11
|
t.notOk(res.headers['access-control-allow-origin'])
|
|
13
|
-
t.end()
|
|
12
|
+
t.end()
|
|
14
13
|
})
|
|
15
14
|
})
|
|
@@ -2,33 +2,27 @@ global.options = {
|
|
|
2
2
|
cache: false // cache invokes a separate path
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
test('does not gzip the response', function(t) {
|
|
22
|
-
t.on('end', function () {
|
|
23
|
-
rimraf(testFile, function () {})
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const crypto = require('crypto')
|
|
8
|
+
const rimraf = require('rimraf')
|
|
9
|
+
const { test } = require('tap')
|
|
10
|
+
const { req } = require('./common.js')
|
|
11
|
+
const testFileName = 'no-gzip-accepted-no-cache.testfile'
|
|
12
|
+
const testFile = path.join(__dirname, '../', testFileName)
|
|
13
|
+
|
|
14
|
+
const rndData = crypto.randomBytes(1024 * 128).toString('hex') // significantly larger than highWaterMark
|
|
15
|
+
|
|
16
|
+
test('does not gzip the response', (t) => {
|
|
17
|
+
t.on('end', () => {
|
|
18
|
+
rimraf(testFile, () => {})
|
|
24
19
|
})
|
|
25
20
|
|
|
26
|
-
fs.writeFile(testFile, rndData,
|
|
27
|
-
t.
|
|
28
|
-
|
|
29
|
-
req('/test/' + testFileName, {'accept-encoding':'none'},
|
|
30
|
-
function (er, res, body) {
|
|
21
|
+
fs.writeFile(testFile, rndData, (err) => {
|
|
22
|
+
t.error(err)
|
|
31
23
|
|
|
24
|
+
req(`/test/${testFileName}`, { 'accept-encoding': 'none' }, (er, res, body) => {
|
|
25
|
+
t.error(er)
|
|
32
26
|
t.equal(res.statusCode, 200)
|
|
33
27
|
t.notOk(res.headers['content-encoding'])
|
|
34
28
|
t.equal(body.toString(), rndData)
|
|
@@ -36,4 +30,3 @@ test('does not gzip the response', function(t) {
|
|
|
36
30
|
})
|
|
37
31
|
})
|
|
38
32
|
})
|
|
39
|
-
|
package/test/no-gzip-accepted.js
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
global.options = {
|
|
2
2
|
}
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
test('does not gzip the response', function(t) {
|
|
20
|
-
t.on('end', function () {
|
|
21
|
-
rimraf(testFile, function () {})
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const crypto = require('crypto')
|
|
7
|
+
const rimraf = require('rimraf')
|
|
8
|
+
const { test } = require('tap')
|
|
9
|
+
const { req } = require('./common.js')
|
|
10
|
+
const testFileName = 'no-gzip-accepted.testfile'
|
|
11
|
+
const testFile = path.join(__dirname, '../', testFileName)
|
|
12
|
+
|
|
13
|
+
const rndData = crypto.randomBytes(1024 * 128).toString('hex') // significantly larger than highWaterMark
|
|
14
|
+
|
|
15
|
+
test('does not gzip the response', (t) => {
|
|
16
|
+
t.on('end', () => {
|
|
17
|
+
rimraf(testFile, () => {})
|
|
22
18
|
})
|
|
23
19
|
|
|
24
|
-
fs.writeFile(testFile, rndData,
|
|
25
|
-
t.
|
|
26
|
-
|
|
27
|
-
req('/test/' + testFileName, {'accept-encoding':'none'},
|
|
28
|
-
function (er, res, body) {
|
|
20
|
+
fs.writeFile(testFile, rndData, (err) => {
|
|
21
|
+
t.error(err)
|
|
29
22
|
|
|
23
|
+
req('/test/' + testFileName, { 'accept-encoding': 'none' }, (er, res, body) => {
|
|
24
|
+
t.error(er)
|
|
30
25
|
t.equal(res.statusCode, 200)
|
|
31
26
|
t.notOk(res.headers['content-encoding'])
|
|
32
27
|
t.equal(body.toString(), rndData)
|
|
@@ -34,4 +29,3 @@ test('does not gzip the response', function(t) {
|
|
|
34
29
|
})
|
|
35
30
|
})
|
|
36
31
|
})
|
|
37
|
-
|
package/test/no-gzip.js
CHANGED
|
@@ -3,21 +3,16 @@ global.options = {
|
|
|
3
3
|
gzip: false
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var mount = basic.mount
|
|
9
|
-
var stExpect = basic.stExpect
|
|
6
|
+
const { test } = require('tap')
|
|
7
|
+
const { req, stExpect } = require('./basic.js')
|
|
10
8
|
|
|
11
9
|
// additional test to ensure that it's actually not gzipping
|
|
12
|
-
var test = require('tap').test
|
|
13
10
|
|
|
14
|
-
test('does not gzip the response',
|
|
15
|
-
req('/test/st.js', {'accept-encoding':'gzip'},
|
|
16
|
-
function (er, res, body) {
|
|
11
|
+
test('does not gzip the response', (t) => {
|
|
12
|
+
req('/test/st.js', { 'accept-encoding': 'gzip' }, (er, res, body) => {
|
|
17
13
|
t.equal(res.statusCode, 200)
|
|
18
14
|
t.notOk(res.headers['content-encoding'])
|
|
19
15
|
t.equal(body.toString(), stExpect)
|
|
20
16
|
t.end()
|
|
21
17
|
})
|
|
22
18
|
})
|
|
23
|
-
|
package/test/parent-path.js
CHANGED