This repository has been archived by the owner on Jul 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: Do not imply a callback to compat res.write
- Loading branch information
Showing
2 changed files
with
106 additions
and
1 deletion.
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
95 changes: 95 additions & 0 deletions
95
test/parallel/test-http2-compat-serverresponse-write-no-cb.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,95 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const h2 = require('http2'); | ||
|
||
// Http2ServerResponse.write does not imply there is a callback | ||
|
||
{ | ||
const server = h2.createServer(); | ||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
const url = `http://localhost:${port}`; | ||
const client = h2.connect(url, common.mustCall(function() { | ||
const headers = { | ||
':path': '/', | ||
':method': 'GET', | ||
':scheme': 'http', | ||
':authority': `localhost:${port}` | ||
}; | ||
const request = client.request(headers); | ||
request.end(); | ||
request.resume(); | ||
})); | ||
|
||
server.once('request', common.mustCall(function(request, response) { | ||
client.destroy(); | ||
response.stream.session.on('close', common.mustCall(function() { | ||
response.on('error', common.mustCall(function(err) { | ||
assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); | ||
})); | ||
response.write('muahaha'); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
const server = h2.createServer(); | ||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
const url = `http://localhost:${port}`; | ||
const client = h2.connect(url, common.mustCall(function() { | ||
const headers = { | ||
':path': '/', | ||
':method': 'get', | ||
':scheme': 'http', | ||
':authority': `localhost:${port}` | ||
}; | ||
const request = client.request(headers); | ||
request.end(); | ||
request.resume(); | ||
})); | ||
|
||
server.once('request', common.mustCall(function(request, response) { | ||
client.destroy(); | ||
response.stream.session.on('close', common.mustCall(function() { | ||
response.write('muahaha', common.mustCall(function(err) { | ||
assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); | ||
})); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
const server = h2.createServer(); | ||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
const url = `http://localhost:${port}`; | ||
const client = h2.connect(url, common.mustCall(function() { | ||
const headers = { | ||
':path': '/', | ||
':method': 'get', | ||
':scheme': 'http', | ||
':authority': `localhost:${port}` | ||
}; | ||
const request = client.request(headers); | ||
request.end(); | ||
request.resume(); | ||
})); | ||
|
||
server.once('request', common.mustCall(function(request, response) { | ||
response.stream.session.on('close', common.mustCall(function() { | ||
response.write('muahaha', 'utf8', common.mustCall(function(err) { | ||
assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); | ||
})); | ||
server.close(); | ||
})); | ||
client.destroy(); | ||
})); | ||
})); | ||
} |