Skip to content

Conversation

@ronag
Copy link
Member

@ronag ronag commented Jun 1, 2019

Adds bytesWritten helper to http/1 & compat response.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jun 1, 2019
Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 request

@addaleax addaleax added http Issues or PRs related to the http subsystem. http2 Issues or PRs related to the http2 subsystem. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Jun 2, 2019
@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch 2 times, most recently from 683804b to 8720c1c Compare June 2, 2019 17:39
@ronag
Copy link
Member Author

ronag commented Jun 2, 2019

Would be nice to add bytesRead to IncomingMessage... but I can't follow the data flow there...

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to require some documentation?

@BridgeAR BridgeAR added the semver-minor PRs that contain new features and should be released in the next minor version. label Jun 4, 2019
@BridgeAR
Copy link
Member

BridgeAR commented Jul 5, 2019

Ping @ronag

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch 2 times, most recently from b627fb5 to 5d10298 Compare July 13, 2019 11:51
@ronag
Copy link
Member Author

ronag commented Jul 13, 2019

@BridgeAR docs added

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from 5d10298 to c5cfabf Compare July 13, 2019 11:51
@Trott
Copy link
Member

Trott commented Jul 14, 2019

@nodejs/http @nodejs/http2

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is compatible with the approach in #27988. If we think we should add bytesRead  to Readable, we should add bytesWritten to Writable.

@ronag
Copy link
Member Author

ronag commented Jul 14, 2019

@mcollina What do you mean? http/1 does not inherit from Readable nor Writable. Or do you mean you are missing the bytesRead?

@mcollina
Copy link
Member

@ronag IncomigMessage inherits from Readable (source

Object.setPrototypeOf(IncomingMessage, Stream.Readable);
). OutgoingMessage does not (but it quacks like it).

I'm -1 in adding bytesWritten here if it's not part of Readable/Writable as well.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from c5cfabf to 7550220 Compare July 14, 2019 11:20
@ronag
Copy link
Member Author

ronag commented Jul 14, 2019

@mcollina I've updated the PR so that the classes that inherit Readable/Writable do not get these props overloaded.

However, OutgoingMessage is supposed to "quack" like a Writable so I still think it's appropriate to add this property (at least until we get so far that we can implemented it through Writable)

@ronag
Copy link
Member Author

ronag commented Jul 27, 2019

Should I give up and close this one?

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch 2 times, most recently from ef314da to d322bc4 Compare July 27, 2019 12:23
@ronag
Copy link
Member Author

ronag commented Jul 27, 2019

not sure, should this be the amount sent to write or the amount that has actually been flushed? @mcollina?

@mcollina
Copy link
Member

mcollina commented Aug 2, 2019

I think we are computing it in the right moment. Bytes written to the stream, not bytes flushed out.

@ronag
Copy link
Member Author

ronag commented Aug 2, 2019

@mcollina: What is left here in order to make this mergable?

@mcollina
Copy link
Member

mcollina commented Aug 2, 2019

Unit tests.

I’m also unsure about the naming.
What happens to this value if the stream is in object mode? Should it be “dataWritten” instead?

@ronag
Copy link
Member Author

ronag commented Aug 2, 2019

Unit tests.

Ok.

I’m also unsure about the naming.
What happens to this value if the stream is in object mode? Should it be “dataWritten” instead?

Yes I was unsure about this myself. What about just written (that's what we call it on the stream state)? dataWritten doesn't feel right to me at least.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from d322bc4 to 86ee44a Compare August 2, 2019 07:40
@mcollina
Copy link
Member

mcollina commented Aug 2, 2019

I would go for writableWritten, even if it sounds bad: written might be too generic and conflict with some other properties.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from 86ee44a to dccba4d Compare August 2, 2019 07:47
@ronag
Copy link
Member Author

ronag commented Aug 2, 2019

Tests added

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch 4 times, most recently from 13157ec to ed38fa8 Compare August 2, 2019 09:17
@mcollina
Copy link
Member

mcollina commented Aug 3, 2019

@addaleax @lpinca how would you call the amount of data (bytes or object) written to a Writable? My best option is writableWritten, which I dislike.

@addaleax
Copy link
Member

addaleax commented Aug 3, 2019

@mcollina I’d really prefer to keep consistency with the existing properties that provide this information, which are called bytesRead and bytesWritten. That might be unfortunate but I think it’s the most consistent and least confusing.

@mcollina
Copy link
Member

mcollina commented Aug 3, 2019

I think we should document and test the behavior of these properties with objectMode: true.

@lpinca
Copy link
Member

lpinca commented Aug 3, 2019

I kind of agree with @addaleax about names.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from ed38fa8 to 499c736 Compare August 24, 2019 10:26
@ronag
Copy link
Member Author

ronag commented Aug 24, 2019

Rebased, cleaned up and fixed test.

What's the consensus in regards to:

  • The naming?
  • should bytesWritten represent the number of objects written in objectMode or should it be null.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch 4 times, most recently from 0f6a4e8 to 3b07f24 Compare August 24, 2019 10:33
@ronag
Copy link
Member Author

ronag commented Aug 24, 2019

This might need a semver-major. We already have bytesWritten on fs streams and there it is/was slightly different/wrong.

@ronag ronag force-pushed the feat-http1-compat-bytesWritten branch from 3b07f24 to 4a01aa8 Compare August 24, 2019 10:35

Integer value that indicates how many bytes has been written to
the response body (not the amount flushed).

Copy link
Member Author

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?

}
return cb(er);
}
this.bytesWritten += bytes;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice that WriteStream increments bytesWritten inside _write() callback and not in write(). I think this is actually wrong and slightly contradicts the previous documentation as well (and possibly expected behaviour, it surprised me).

self.destroy();
return cb(er);
}
self.bytesWritten += bytes;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

@ronag
Copy link
Member Author

ronag commented Aug 26, 2019

I'm closing this for now.

@ronag ronag closed this Aug 26, 2019
@ronag ronag changed the title http: bytesWritten for http/1 and compat [x] http: bytesWritten for http/1 and compat Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. http2 Issues or PRs related to the http2 subsystem. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants