Need to connect to web socket server with cookie
I need to connect to a websocket server with the outgoing initial HTTP request containing a cookie. Is this possible? I didn't see any options in MqttClientOptionsBuilder.
I believe this is related to #496.
I was able to do this by creating a MqttClientWebSocketOptions class and attaching a CookieContainer, then assigning this to ChannelOptions of a manually created MqttClientOptions class.
In other words this is possible without using the builder, but it'd be nice if there was an override that included a cookie container on WithWebSocketServer() extension.
Not sure, if cookies are passed through request headers, but while adding the option for headers, I will also add an overload for the CookieContainer. As @djarvis says, a MqttClientWebSocketOptions class could be passed in the builder the same way as is done with MqttClientOptionsBuilderTlsParameters.
All while leaving the default call with only the url for backwards compatibility
I just tested this and I do get cookies back to the client from the connect call, and when I set them they are also recognized on the server.
I am doing this because, in scaled Azure instances, I wish to target specific instances of my MQTT broker behind the load balancer. I can tell which instance the client is talking to by observing the ARRAffinity cookie in my cookie collection, and I can also target a specific instance to connect with by setting the cookie.
It's all wonderfully awesome.
@djarvis I've just created a pull request allowing to pass the cookies and request headers if you want to check it out
I assume that this is done. Please re-open this issue or comment if you have any concerns, @djarvis.