-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
[x] http: bytesWritten for http/1 and compat #28004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,7 +250,6 @@ function WriteStream(path, options) { | |
| this.start = options.start; | ||
| this.autoClose = options.autoClose === undefined ? true : !!options.autoClose; | ||
| this.pos = undefined; | ||
| this.bytesWritten = 0; | ||
| this.closed = false; | ||
|
|
||
| if (this.start !== undefined) { | ||
|
|
@@ -312,7 +311,6 @@ WriteStream.prototype._write = function(data, encoding, cb) { | |
| } | ||
| return cb(er); | ||
| } | ||
| this.bytesWritten += bytes; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notice that WriteStream increments bytesWritten inside |
||
| cb(); | ||
| }); | ||
|
|
||
|
|
@@ -345,7 +343,6 @@ WriteStream.prototype._writev = function(data, cb) { | |
| self.destroy(); | ||
| return cb(er); | ||
| } | ||
| self.bytesWritten += bytes; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. |
||
| cb(); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
|
|
||
| const server = http.createServer(common.mustCall(function(req, res) { | ||
| res.setHeader('test-header', 'header'); | ||
| assert.strictEqual(res.bytesWritten, 0); | ||
| res.write('hello'); | ||
| assert.strictEqual(res.bytesWritten, 5); | ||
| res.end('world'); | ||
| assert.strictEqual(res.bytesWritten, 10); | ||
| server.close(); | ||
| })); | ||
|
|
||
| server.listen(0); | ||
|
|
||
| server.on('listening', common.mustCall(function() { | ||
| const clientRequest = http.request({ | ||
| port: server.address().port, | ||
| method: 'GET', | ||
| path: '/' | ||
| }); | ||
| clientRequest.end(); | ||
| })); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| if (!common.hasCrypto) | ||
| common.skip('missing crypto'); | ||
| const assert = require('assert'); | ||
| const h2 = require('http2'); | ||
|
|
||
| const server = h2.createServer(common.mustCall(function(req, res) { | ||
| res.setHeader('test-header', 'header'); | ||
| assert.strictEqual(res.bytesWritten, 0); | ||
| res.write('hello'); | ||
| assert.strictEqual(res.bytesWritten, 5); | ||
| res.end('world'); | ||
| assert.strictEqual(res.bytesWritten, 10); | ||
| server.close(); | ||
| })); | ||
|
|
||
| server.listen(0); | ||
|
|
||
| server.on('listening', common.mustCall(function() { | ||
| const url = `http://localhost:${server.address().port}`; | ||
| const client = h2.connect(url, common.mustCall(() => { | ||
| const request = client.request(); | ||
| request.end(); | ||
| })); | ||
| })); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const { Writable } = require('stream'); | ||
| const assert = require('assert'); | ||
|
|
||
| { | ||
| const writable = new Writable({ | ||
| write: (buf, enc, cb) => { | ||
| cb(); | ||
| } | ||
| }); | ||
| assert.strictEqual(writable.bytesWritten, 0); | ||
| writable.write('hello'); | ||
| assert.strictEqual(writable.bytesWritten, 5); | ||
| writable.end('world'); | ||
| assert.strictEqual(writable.bytesWritten, 10); | ||
| } | ||
|
|
||
| { | ||
| const writable = new Writable({ | ||
| objectMode: true, | ||
| write: (buf, enc, cb) => { | ||
| cb(); | ||
| } | ||
| }); | ||
| assert.strictEqual(writable.bytesWritten, 0); | ||
| writable.write({}); | ||
| assert.strictEqual(writable.bytesWritten, 1); | ||
| writable.end({}); | ||
| assert.strictEqual(writable.bytesWritten, 2); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need this here since WriteStream inherits from Writable which now documents this property? Remove?