-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
fix(ClientRequest): throw when writing after end for bypass responses #462
base: main
Are you sure you want to change the base?
Changes from 1 commit
103f8c3
8204bd9
def1a6b
896f6c2
fe9fe5d
ad67406
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 |
---|---|---|
|
@@ -99,6 +99,11 @@ export class NodeClientRequest extends ClientRequest { | |
} | ||
|
||
write(...args: ClientRequestWriteArgs): boolean { | ||
// Fallback to native behavior to throw | ||
if (this.destroyed || this.finished) { | ||
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. I believe neither of these properties will be set immediately after calling Given the current limitations, I think the most straightforward way to fix this is to have an internal write(...) {
if (this.requestSent) {
throwNodeWriteAfterEndError()
}
}
end(...) {
// Mark the request as sent immediately so
// the interceptor would know to stop buffering
// ".write()" calls after this point: that's a no-op.
this.requestSent = true
} What do you think about this? I dislike introducing any new state but I don't suppose we can rely on request properties since those we need are set async anyway:
And both happen asynchronously after the request listener promise settles. 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. I agree! I dislike this as well. We can alternate the
But I think this is more confusing and error-prone than a new state. 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. Alas, we can't 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. And we'd likely have to recreate the original Node.js error here because calling It shouldn't be hard replicating the Node's native error. |
||
return super.write(args) | ||
} | ||
|
||
const [chunk, encoding, callback] = normalizeClientRequestWriteArgs(args) | ||
this.logger.info('write:', { chunk, encoding, callback }) | ||
this.chunks.push({ chunk, encoding }) | ||
|
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 think this should be a compliance test in
test/modules/http/compliance
where we will also feature the real usage ofhttp.*
instead of constructing the internal class.