-
Notifications
You must be signed in to change notification settings - Fork 2k
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
exposing proxySocket on socket to support sniffing messages coming from proxy target #706
Conversation
@thlorenz what if we emit the proxySocket in an event on the |
@jcrugzz that'd be even better cause then I'd know when I can subscribe to its event instead of having to test if its there yet or not. Do you want me to update the PR to do that? Only question is what's our event emitter? The only one I see inside Any other emitters you see? |
Well, I guess the
obviously that'd be ideal, but I don't see that we have access to it from within |
@thlorenz naming is just terrible here. The |
OK, will update the PR tonight (will just rewrite it). |
@thlorenz make it |
I updated the PR to emit the Hope that's ok. |
- emitted once proxySocket was created and socket was piped into it - needed to support sniffing messages coming from proxy target
LGTM |
exposing proxySocket on socket to support sniffing messages coming from proxy target
@thlorenz thanks! |
@@ -108,6 +108,7 @@ var passes = exports; | |||
return i + ": " + proxyRes.headers[i]; | |||
}).join('\r\n') + '\r\n\r\n'); | |||
proxySocket.pipe(socket).pipe(proxySocket); | |||
server.emit('proxySocket', proxySocket); |
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 get TypeError: Object false has no method 'emit'
on this line in my code.
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.
That is odd, why would the server be a boolean
?
We could add a check to keep in from blowing up:
if (typeof server.emit === 'function') server.emit('proxySocket', proxySocket);
but then it'd still suck cause it would emit only sometimes.
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.
It may well be a bug in my code. I create an HTTP server separately, and register proxy methods in its handlers.
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.
Ahh i missed that, fixed in 1.5.1. Its because when a callback is used on the web
or ws
method, it doesn't pass the instance into the function. Sub-ideal as it is always an event emitter instance now but it didn't always use to be.
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.
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.
@jcrugzz thanks for fixing and sorry I missed that myself as well.
I'm a little confused as to how people are making use of this feature (renamed to (Use case: we're proxying to many backends, and want to place a |
@glasser id be ok with emitting multiple arguments on that event. Submit a PR with an ordering that makes sense. |
Basically I need access to the proxySocket in order to listen to messages coming back.
I realize the implementation is a bit hacky, but it's the only way I could think of ATM. I'm open for other suggestions.
Here is an example use case taken from chromium-remote-debugging-proxy
If there is an existing way to make this work, please let me know as well.