rumqtt icon indicating copy to clipboard operation
rumqtt copied to clipboard

Add User-Agent header to initial HTTP request when using WebSockets

Open rajivshah3 opened this issue 3 years ago • 1 comments
trafficstars

Happy new year! We'd like to be able to pass a value to be used as the User-Agent header for the initial HTTP request before upgrading to a WebSocket:

https://github.com/bytebeamio/rumqtt/blob/4b76fc024dedc48428160bd59a03f160b2107277/rumqttc/src/eventloop.rs#L288-L293

I'm happy to make a PR for this change if you'd like. Just a couple of questions:

  • What would be the best way to expose this through the API? I guess via MqttOptions?
  • Should there be a default user agent if one isn't specified?

rajivshah3 avatar Jan 01 '22 18:01 rajivshah3

Hey @rajivshah3, sorry for the late reply. We'd be happy to receive a PR and get it merged! As for the questions you have posed, it'd be a great idea to have a method on MqttOptions that works like this:

options.set_user_agent("...")

As for the implementation, we could use an Option<T> inside MqttOptions which will have a Some(...) that can be then used when creating the request. The default behavior might as well be better not to set a user-agent header, if let Some(agent) = options.user_agent() { request_builder = request_builder.header("User-Agent", agent); }.

de-sh avatar Feb 10 '22 06:02 de-sh

Hey, I was just checking out older issues, and stumbled on this.

rumqttc v0.23.0 onwards, we can set request modifier function using: ( added in #642 ) https://github.com/bytebeamio/rumqtt/blob/5748d451d485bda7fd84e0c983ade793b3fda87b/rumqttc/src/lib.rs#L710

So modifying requests like adding headers can be done there :)

Will be closing the issue in favor of this, feel free to reopen if required, thanks for pointing it out and your contribution :rocket:

swanandx avatar Jan 16 '24 09:01 swanandx