-
-
Notifications
You must be signed in to change notification settings - Fork 675
feat: dump interceptor #3118
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
feat: dump interceptor #3118
Changes from 7 commits
6d975ea
5024ae1
befe478
da70cbd
62a4cde
d82b51b
33b7126
e3190f1
2fd173d
85af461
f5cc824
675c261
c43c80c
8548c8e
84c0d8b
13ba7e0
bf75a5b
8607411
428a953
8fae866
4492ab7
cc42e2d
c60ee90
38b24fb
fb4ccd8
0d67095
e60add7
3a68023
3e3295f
2265a19
ae685cf
85ab3d6
fb5af55
ab67b1b
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||||||||||
| 'use strict' | ||||||||||||||||||
|
|
||||||||||||||||||
| const util = require('../core/util') | ||||||||||||||||||
| const { InvalidArgumentError, RequestAbortedError } = require('../core/errors') | ||||||||||||||||||
|
|
||||||||||||||||||
| class DumpHandler { | ||||||||||||||||||
metcoder95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| res = null | ||||||||||||||||||
| maxSize = 1024 * 1024 | ||||||||||||||||||
ronag marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| #abort = null | ||||||||||||||||||
| #aborted = false | ||||||||||||||||||
| #size = 0 | ||||||||||||||||||
| #contentLength = 0 | ||||||||||||||||||
| #reason = null | ||||||||||||||||||
| #handler = null | ||||||||||||||||||
|
|
||||||||||||||||||
| constructor ({ maxSize }, handler) { | ||||||||||||||||||
| if (maxSize != null && (!Number.isFinite(maxSize) || maxSize < 1)) { | ||||||||||||||||||
| throw new InvalidArgumentError('maxSize must be a number greater than 0') | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| this.maxSize = maxSize ?? this.maxSize | ||||||||||||||||||
| this.#handler = handler | ||||||||||||||||||
|
|
||||||||||||||||||
| // Handle possible onConnect duplication | ||||||||||||||||||
| this.#handler.onConnect(reason => { | ||||||||||||||||||
| this.#aborted = true | ||||||||||||||||||
| if (this.#abort != null) { | ||||||||||||||||||
| this.#abort(reason) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| this.#reason = reason | ||||||||||||||||||
| } | ||||||||||||||||||
| }) | ||||||||||||||||||
metcoder95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| onConnect (...args) { | ||||||||||||||||||
| const [abort] = args | ||||||||||||||||||
metcoder95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| if (this.#aborted) { | ||||||||||||||||||
| abort(this.#reason) | ||||||||||||||||||
| return | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| if (this.#aborted) { | |
| abort(this.#reason) | |
| return | |
| } | |
| if (this.#aborted) { | |
| abort(this.#reason) | |
| return | |
| } |
This can't happen?
metcoder95 marked this conversation as resolved.
Show resolved
Hide resolved
metcoder95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ronag marked this conversation as resolved.
Show resolved
Hide resolved
metcoder95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ronag marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
Suggestions? I might be had it wrong here 🤔
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.
you must keep the data flowing from the request or error/abort it. The latter will destroy the connection. It should be a user choice, but I would error/abort the socket by default.
Uh oh!
There was an error while loading. Please reload this page.