Skip to content
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

How to use with WebSockets #125

Closed
matiasmarcodelpont opened this issue May 13, 2023 · 1 comment
Closed

How to use with WebSockets #125

matiasmarcodelpont opened this issue May 13, 2023 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@matiasmarcodelpont
Copy link

My http client authenticates with the server using a bearer token sent on an Authentication header. I have implemented an interceptor and a retry policy to handle the logic when the token must be refreshed.

Now I want to use te same InterceptedClient to create a WebSocket with the same server. The request uses the same Authentication header and must be updated in the same manner.

Is this possible?

@matiasmarcodelpont matiasmarcodelpont added the question Further information is requested label May 13, 2023
@CodingAleCR
Copy link
Owner

I don't think it is possible to do so since HTTP (https://) and WebSocket (ws://) are two different protocols.

WebSocket is a framed and bidirectional protocol. On the contrary, to this, HTTP is a unidirectional protocol functioning above the TCP protocol.

  • WebSocket protocol is capable to support continual data transmission, it’s majorly used in real-time application development.
  • HTTP is stateless and is used for the development of RESTful and SOAP applications.

That said, this package is built on top of http which was not thought for handling websockets. I think your best approach might be to abstract the behavior for token usage to a separate class and use/reuse the same instance in both http and websocket calls or try to find an alternative and more robust package that handles both scenarios (sad but true 😞 )

@CodingAleCR CodingAleCR pinned this issue Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants