-
Notifications
You must be signed in to change notification settings - Fork 30k
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
http: add bytesWritten property #36964
Conversation
Adds a bytesWritten property which can be used to inspect how many bytes have been dispatched to response body.
@nodejs/http @nodejs/http2 |
bab048b
to
92a6b87
Compare
This is quite commonly implemented in user land to different degrees of correctness. |
Co-authored-by: Darshan Sen <raisinten@gmail.com>
get() { | ||
return this[kBytesWritten]; | ||
} | ||
}); |
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.
Could this break userland which extend e.g. ServerResponse
and add this themselves?
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.
Not sure. Maybe some web framework listed in https://github.com/nodejs/citgm/blob/main/lib/lookup.json? I think we could also try some HTTP clients like got
.
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.
I added a setter as well to try and avoid breaking
Does this have a noticeable performance impact? |
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.
My experience with Buffer.byteLength is that it slowish.
I don't necessarily see this as something worth the penalty (if any).
@mcollina: How about now? This should be negligable. |
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.
I fear this would even be worse :/
I can resolve this by overriding |
Ah, I can solve this in userland using |
Adds a bytesWritten property which can be used to inspect
how many bytes have been dispatched to response body.