MCPcopy
hub / github.com/nodejs/undici / writeBodyStartedWithBody

Function writeBodyStartedWithBody

test/node-test/abort-controller.js:220–247  ·  view source on GitHub ↗
(body, type)

Source from the content-addressed store, hash-verified

218 writeHeadersStartedWithBody(wrapWithAsyncIterable(createReadStream(__filename)), 'async-iterator')
219
220 function writeBodyStartedWithBody (body, type) {
221 test(`Abort ${controllerName} while waiting response (write headers and write body started) (with body ${type})`, async (t) => {
222 const p = tspl(t, { plan: 2 })
223
224 const abortController = new AbortControllerImpl()
225 const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
226 res.writeHead(200, { 'content-type': 'text/plain' })
227 res.write('hello')
228 })
229 t.after(closeServerAsPromise(server))
230
231 server.listen(0, () => {
232 const client = new Client(`http://localhost:${server.address().port}`)
233 t.after(client.destroy.bind(client))
234
235 client.request({ path: '/', method: 'POST', body, signal: abortController.signal }, (err, response) => {
236 p.ifError(err)
237 response.body.on('data', () => {
238 abortController.abort()
239 })
240 response.body.on('error', err => {
241 p.ok(err instanceof errors.RequestAbortedError || err instanceof DOMException)
242 })
243 })
244 })
245 await p.completed
246 })
247 }
248
249 writeBodyStartedWithBody('hello', 'string')
250 writeBodyStartedWithBody(createReadStream(__filename), 'stream')

Callers 1

Calls 8

createServerFunction · 0.85
closeServerAsPromiseFunction · 0.85
listenMethod · 0.80
okMethod · 0.80
abortMethod · 0.65
writeMethod · 0.45
requestMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…