GeezerVison is showing github.com — http2: add `bytesWritten` test for `Http2Stream` · nodejs/node@41c5524
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | +const assert = require('assert'); |
| 7 | +const http2 = require('http2'); |
| 8 | + |
| 9 | +const http2Server = http2.createServer(common.mustCall(function(req, res) { |
| 10 | + res.socket.on('finish', common.mustCall(() => { |
| 11 | + assert(req.socket.bytesWritten > 0); // 1094 |
| 12 | + })); |
| 13 | + res.writeHead(200, { 'Content-Type': 'text/plain' }); |
| 14 | + res.write(Buffer.from('1'.repeat(1024))); |
| 15 | + res.end(); |
| 16 | +})); |
| 17 | + |
| 18 | +http2Server.listen(0, common.mustCall(function() { |
| 19 | + const URL = `http://localhost:${http2Server.address().port}`; |
| 20 | + const http2client = http2.connect(URL, { protocol: 'http:' }); |
| 21 | + const req = http2client.request({ ':method': 'GET', ':path': '/' }); |
| 22 | + req.on('data', common.mustCall()); |
| 23 | + req.on('end', common.mustCall(function() { |
| 24 | + http2client.close(); |
| 25 | + http2Server.close(); |
| 26 | + })); |
| 27 | + req.end(); |
| 28 | +})); |