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

Update Headers on Reconnect #282

Closed
smitt04 opened this issue Feb 18, 2019 · 7 comments
Closed

Update Headers on Reconnect #282

smitt04 opened this issue Feb 18, 2019 · 7 comments

Comments

@smitt04
Copy link
Contributor

smitt04 commented Feb 18, 2019

I am connecting to aws IoT using a custom authorizer. To do this i am using the SetHTTPHeaders to add additional headers during connection. It would be nice if we could also do this on reconnect. There is a way to provide credentials on reconnect but that doesn't work for me, need to add additional headers.

@smitt04
Copy link
Contributor Author

smitt04 commented Jun 10, 2021

any interest in this?

@MattBrittan
Copy link
Contributor

Sorry for not replying earlier (somehow missed this one; there have been significant changes since it was raised!). c.options.OnConnectAttempt was added very recently in #497; as there will only be one or two people using this I think that adding the ability to set headers in this call would be OK if you want to submit a PR?

@smitt04
Copy link
Contributor Author

smitt04 commented Jun 10, 2021

I was just looking through my code and realized I had a comment about this issue, so I decided to look into it again. Didn't realize that 1.3+ has been released. I was looking at the changes and noticed this PR which is basically what I am looking for I think? I would have to test it. Do you think that would work? or should we update the c.options.OnConnectAttempt function to also call the same?

For my use case I get my auth first then create the connection by setting headers. I was never able to use auto reconnect because It would try to reconnect with a bad auth token. With the OnReconnecting callback i should be able to update the token before continuing

@MattBrittan
Copy link
Contributor

I think c.options.OnConnectAttempt will need to be changed because the client maintains a private copy of the options (c.options) so you will not be able to edit c.options.HTTPHeaders that from within the current call. I wonder if it would make more sense to just pass c.options to c.options.OnConnectAttempt (and perhaps accept the options back and take a copy of them - modifying these while the library is running could cause all kinds of issues). However this may be a little confusing as attemptConnection() takes a copy of c.options.Servers so it would not be possible to change the servers.

@MattBrittan
Copy link
Contributor

Sorry - just noticed that you were talking about OnReconnecting not OnConnectAttempt. That should do the trick (so I think the change you requested is already in place).

@smitt04
Copy link
Contributor Author

smitt04 commented Jun 10, 2021

Yes, i forgot to post the link to #283

@smitt04
Copy link
Contributor Author

smitt04 commented Jun 10, 2021

#283 fixes the issues of reconnection headers by adding the headers on reconnection attempt. Will re-open if it does not work for my use case. Thanks.

@smitt04 smitt04 closed this as completed Jun 10, 2021
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

2 participants