Repository navigation
Expand file tree
/
Copy pathissue-3356.js
More file actions
96 lines (75 loc) · 2.36 KB
/
Copy pathissue-3356.js
File metadata and controls
96 lines (75 loc) · 2.36 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict'
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { createServer } = require('node:http')
const { once } = require('node:events')
const { fetch, Agent, RetryAgent } = require('..')
test('https://github.com/nodejs/undici/issues/3356', async (t) => {
t = tspl(t, { plan: 3 })
let callCount = 0
const server = createServer({ joinDuplicateHeaders: true })
server.on('request', (req, res) => {
res.writeHead(200, { 'content-type': 'text/plain' })
res.flushHeaders()
res.write('h')
if (callCount++ === 0) {
res.write('ahahaha')
// never end the response
} else {
t.fail('should not be called twice')
}
})
await once(server.listen(0), 'listening')
after(() => once(server.close(), 'close'))
const agent = new RetryAgent(new Agent({ bodyTimeout: 50 }), {
errorCodes: ['UND_ERR_BODY_TIMEOUT']
})
const response = await fetch(`http://localhost:${server.address().port}`, {
dispatcher: agent
})
t.equal(response.status, 200)
try {
await response.text()
t.fail('should have thrown')
} catch (err) {
t.equal(err.name, 'TypeError')
t.equal(err.cause.code, 'UND_ERR_BODY_TIMEOUT')
}
await t.completed
})
test('https://github.com/nodejs/undici/issues/3356', { skip: true }, async (t) => {
t = tspl(t, { plan: 2 })
let callCount = 0
const server = createServer({ joinDuplicateHeaders: true })
server.on('request', (req, res) => {
if (callCount++ === 0) {
res.writeHead(206, {
'content-type': 'text/plain',
'content-range': 'bytes 0-12/12'
})
res.flushHeaders()
res.write('h')
// never end the response
} else if (callCount === 1) {
console.log(req.headers['accept-ranges'])
res.writeHead(206, {
'content-type': 'text/plain',
'content-range': 'bytes 1-12/12'
})
res.flushHeaders()
res.write('ello world!')
res.end()
}
})
await once(server.listen(0), 'listening')
after(() => once(server.close(), 'close'))
const agent = new RetryAgent(new Agent({ bodyTimeout: 50 }), {
errorCodes: ['UND_ERR_BODY_TIMEOUT']
})
const response = await fetch(`http://localhost:${server.address().port}`, {
dispatcher: agent
})
t.equal(response.status, 206)
t.equal(await response.text(), 'hello world!')
await t.completed
})