-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Can we update headers for next reconnect state? #99
Comments
Let me describe in more detail. When connecting to the centrifuge, we have an additional intermediate layer.
When an error occurs at stage 1, for example, if the passed key is invalid or expired, the client receives a response not as from WebSocket, but as from a regular "REST" request. In other words, during the connection establishment, we expect a response with a code 101, but we can receive anything. The library is currently not designed to handle such types of errors, or rather, it's not fully prepared. StarscreamWebSocketIt has access to all data being sent and received, so when the above error occurs, you determine the "Invalid HTTP upgrade" state, retrieve the received code from the server, and pass it. As a result, StarscreamWebSocket passes the current response code from the server, but replaces the response with "Invalid HTTP upgrade". It would be beneficial to have an option to gain access to the server's message as well, providing the ability to retrieve both the response code and the server message. NativeWebSocketHere it's more complex, as it utilizes a system implementation and many details are hidden. func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
assertIsOnQueue(queue)
guard let task = task as? URLSessionWebSocketTask, task === self.task else {
// Ignore callbacks from obsolete tasks
return
}
handleTaskClose(task: task, code: task.closeCode, reason: task.closeReason, error: error)
} In this case error, task.closeCode, and task.closeReason are not entirely informative. In this scenario, the required states can only be obtained from the current response - task.response. The client embedding the SDK using NativeWebSocket only perceives that the connection is not established. Even if the server sends informative responses, they won't be accessible. The response code and content are concealed within the task.response field and are not passed through. |
I've played around with the library code a bit, and technically, there's a possibility to update headers so that new ones are used upon the next connection. I've tested this, and it works for both implementations. Here my code for headers updating: |
Hi
We're dealing with a scenario where we connect to a centrifuge via a middleware. This middleware verifies our authentication using a value in the headers. The authentication value in the headers has a limited lifetime, so we must update it in the client's headers for the next reconnect.
Is it currently impossible? Perhaps you could suggest a workaround?
Thank you
The text was updated successfully, but these errors were encountered: