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

Improvements to Custom Headers #426

Closed
Laptopmini opened this issue Nov 21, 2017 · 3 comments
Closed

Improvements to Custom Headers #426

Laptopmini opened this issue Nov 21, 2017 · 3 comments

Comments

@Laptopmini
Copy link

First off, thanks for the work, this is a great library. Clean & Efficient.

With the recent disappearance of the .headers variable, I encountered a slight problem for which I thought I should mention some potential improvements.

Use Case (Simplified)

I need to connect to a websocket using an authentication token, which is passed in the headers of the websocket's request. When my WebsocketManager class is initialized it creates a variable for the websocket.

self.eventSocket = WebSocket(url: SocketEndPoint.events.url)

This variable will not connect just yet, we will first have to wait for a certain user flow(s) to complete. Once that is done, I have the correct token to initiate the connection. In the past I would do the following

self.eventSocket.headers[HeaderKeys.auth.rawValue] = token.getHeaderValue()
self.eventSocket.connect()

This token is subject to changes, in which case the socket is disconnected (if not already done by the server), and I repeat the code shown right above to set the header of eventSocket to the latest token available and re-establish the connection.

Issue

With the latest version, this is not possible. The only alternative I've found is to create a new WebSocket instance and to init it with a brand new request which includes the latest header value. This is ok, but wasteful.

Improvements

At first, I thought I could just subclass WebSocket and implement my own helper methods to update this header, but this is not possible due to request being private.

Here are some improvements, any of which would resolve my problem:

  • Make request public.
  • Add convenience method to set a header to the request post init.
  • Add back support for .headers which would be parsed within createHTTPRequest().

Related Issues

#387

@daltoniam
Copy link
Owner

Version 3.0.3 has just been released that made the URLRequest object public.

@Laptopmini
Copy link
Author

Thanks! 👍

@nahung89
Copy link

great! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants