fix: registerStreamProtocol callback with large chunks (#16532)

This commit is contained in:
Jeremy Apthorp 2019-01-25 10:57:26 -08:00 committed by GitHub
parent 8396a2d504
commit 63bf370cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -654,6 +654,30 @@ describe('protocol module', () => {
})
})
})
it('can handle large responses', async () => {
const data = Buffer.alloc(128 * 1024)
const handler = (request, callback) => {
callback(getStream(data.length, data))
}
await new Promise((resolve, reject) => {
protocol.registerStreamProtocol(protocolName, handler, err => {
if (err) return reject(err)
resolve()
})
})
const r = await new Promise((resolve, reject) => {
$.ajax({
url: protocolName + '://fake-host',
cache: false,
success: resolve,
error: (xhr, errorType, error) => {
reject(error || new Error(`Request failed: ${xhr.status}`))
}
})
})
assert.strictEqual(r.length, data.length)
})
})
describe('protocol.isProtocolHandled', (done) => {