-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add upgrade request/response callbacks #132
Add upgrade request/response callbacks #132
Conversation
These callbacks are invoked during the handshake just before the upgrade request is sent and just after the response is received.
305bf9d
to
f3682e8
Compare
@@ -820,6 +830,10 @@ func (s *WebsocketStream) upgrade( | |||
} | |||
s.hb = s.hb[:0] | |||
|
|||
if s.upResCb != nil { |
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.
shouldn't this be called after we assert that the handshake response is valid below? Or is there a use-case to snoop into a potentially invalid response?
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.
The latter. The main motivation for this is to be able to log the request/response so we can debug failed handshakes.
// just before the upgrade request is sent. | ||
// | ||
// The caller must not perform any operations on the stream in the provided callback. | ||
SetUpgradeRequestCallback(callback UpgradeRequestCallback) |
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'm guessing this is here in order to provide the http.Request
to the caller for potential modification... which for the handshake means adding more headers. If so, we already have this mechanism of adding extra headers to the handshake, see here (this is used in bullish iirc)
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's for logging the request (at least for my use case).
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.
Don't think the request callback is needed. The response one is ok, pending the question whether it should be invoked on a potentially wrong handshake response as well
These callbacks are invoked during the handshake just before the upgrade request is sent and just after the response is received.