-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: fix condition where data is lost
- Loading branch information
Showing
3 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/parallel/test-http2-compat-short-stream-client-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const { Readable } = require('stream'); | ||
|
||
const server = http2.createServer(common.mustCall((req, res) => { | ||
res.setHeader('content-type', 'text/html'); | ||
const input = new Readable({ | ||
read() { | ||
this.push('test'); | ||
this.push(null); | ||
} | ||
}); | ||
input.pipe(res); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const client = http2.connect(`http://localhost:${port}`); | ||
|
||
const req = client.request(); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 200); | ||
assert.strictEqual(headers['content-type'], 'text/html'); | ||
})); | ||
|
||
let data = ''; | ||
|
||
const notCallClose = common.mustNotCall(); | ||
|
||
setTimeout(() => { | ||
req.setEncoding('utf8'); | ||
req.removeListener('close', notCallClose); | ||
req.on('close', common.mustCall(() => { | ||
server.close(); | ||
client.close(); | ||
})); | ||
req.on('data', common.mustCallAtLeast((d) => data += d)); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, 'test'); | ||
})); | ||
}, common.platformTimeout(100)); | ||
|
||
req.on('close', notCallClose); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const { Readable } = require('stream'); | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream) => { | ||
stream.respond({ | ||
':status': 200, | ||
'content-type': 'text/html' | ||
}); | ||
const input = new Readable({ | ||
read() { | ||
this.push('test'); | ||
this.push(null); | ||
} | ||
}); | ||
input.pipe(stream); | ||
})); | ||
|
||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const client = http2.connect(`http://localhost:${port}`); | ||
|
||
const req = client.request(); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 200); | ||
assert.strictEqual(headers['content-type'], 'text/html'); | ||
})); | ||
|
||
let data = ''; | ||
|
||
const notCallClose = common.mustNotCall(); | ||
|
||
setTimeout(() => { | ||
req.setEncoding('utf8'); | ||
req.removeListener('close', notCallClose); | ||
req.on('close', common.mustCall(() => { | ||
server.close(); | ||
client.close(); | ||
})); | ||
req.on('data', common.mustCallAtLeast((d) => data += d)); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, 'test'); | ||
})); | ||
}, common.platformTimeout(100)); | ||
|
||
req.on('close', notCallClose); | ||
})); |