|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const h2 = require('http2'); |
| 6 | + |
| 7 | +// Http2ServerResponse.write does not imply there is a callback |
| 8 | + |
| 9 | +{ |
| 10 | + const server = h2.createServer(); |
| 11 | + server.listen(0, common.mustCall(function() { |
| 12 | + const port = server.address().port; |
| 13 | + const url = `http://localhost:${port}`; |
| 14 | + const client = h2.connect(url, common.mustCall(function() { |
| 15 | + const headers = { |
| 16 | + ':path': '/', |
| 17 | + ':method': 'GET', |
| 18 | + ':scheme': 'http', |
| 19 | + ':authority': `localhost:${port}` |
| 20 | + }; |
| 21 | + const request = client.request(headers); |
| 22 | + request.end(); |
| 23 | + request.resume(); |
| 24 | + })); |
| 25 | + |
| 26 | + server.once('request', common.mustCall(function(request, response) { |
| 27 | + client.destroy(); |
| 28 | + response.stream.session.on('close', common.mustCall(function() { |
| 29 | + response.on('error', common.mustCall(function(err) { |
| 30 | + assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); |
| 31 | + })); |
| 32 | + response.write('muahaha'); |
| 33 | + server.close(); |
| 34 | + })); |
| 35 | + })); |
| 36 | + })); |
| 37 | +} |
| 38 | + |
| 39 | +{ |
| 40 | + const server = h2.createServer(); |
| 41 | + server.listen(0, common.mustCall(function() { |
| 42 | + const port = server.address().port; |
| 43 | + const url = `http://localhost:${port}`; |
| 44 | + const client = h2.connect(url, common.mustCall(function() { |
| 45 | + const headers = { |
| 46 | + ':path': '/', |
| 47 | + ':method': 'get', |
| 48 | + ':scheme': 'http', |
| 49 | + ':authority': `localhost:${port}` |
| 50 | + }; |
| 51 | + const request = client.request(headers); |
| 52 | + request.end(); |
| 53 | + request.resume(); |
| 54 | + })); |
| 55 | + |
| 56 | + server.once('request', common.mustCall(function(request, response) { |
| 57 | + client.destroy(); |
| 58 | + response.stream.session.on('close', common.mustCall(function() { |
| 59 | + response.write('muahaha', common.mustCall(function(err) { |
| 60 | + assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); |
| 61 | + })); |
| 62 | + server.close(); |
| 63 | + })); |
| 64 | + })); |
| 65 | + })); |
| 66 | +} |
| 67 | + |
| 68 | +{ |
| 69 | + const server = h2.createServer(); |
| 70 | + server.listen(0, common.mustCall(function() { |
| 71 | + const port = server.address().port; |
| 72 | + const url = `http://localhost:${port}`; |
| 73 | + const client = h2.connect(url, common.mustCall(function() { |
| 74 | + const headers = { |
| 75 | + ':path': '/', |
| 76 | + ':method': 'get', |
| 77 | + ':scheme': 'http', |
| 78 | + ':authority': `localhost:${port}` |
| 79 | + }; |
| 80 | + const request = client.request(headers); |
| 81 | + request.end(); |
| 82 | + request.resume(); |
| 83 | + })); |
| 84 | + |
| 85 | + server.once('request', common.mustCall(function(request, response) { |
| 86 | + response.stream.session.on('close', common.mustCall(function() { |
| 87 | + response.write('muahaha', 'utf8', common.mustCall(function(err) { |
| 88 | + assert.strictEqual(err.message, 'HTTP/2 Stream has been closed'); |
| 89 | + })); |
| 90 | + server.close(); |
| 91 | + })); |
| 92 | + client.destroy(); |
| 93 | + })); |
| 94 | + })); |
| 95 | +} |
0 commit comments