httptoolkit / httptoolkit

HTTP Toolkit is a beautiful & open-source tool for debugging, testing and building with HTTP(S) on Windows, Linux & Mac :tada: Open an issue here to give feedback or ask for help.
https://httptoolkit.com
2.62k stars 70 forks source link

Add support for mqtt protocol #254

Open actuaIIy opened 2 years ago

actuaIIy commented 2 years ago

Please add support for mqtt websockets, pretty sure quite some people would want this implemented.

actuaIIy commented 2 years ago

image this is what I currently see upon a mqtt connection

pimterry commented 2 years ago

Hi @actuaIIy, good suggestion! I'd love to widen the protocol support.

It's unlikely that this is going to happen immediately because it's quite a lot of work, but it would definitely be interesting to investigate further.

Can you share some more info about what kinds of MQTT traffic you're interested in and why?

andreavalle commented 1 year ago

I'm also interested in MQTT support, and in general anyone testing IoT apps would require MQTT support. MQTT is a publish and subscribe protocol. Typically an IoT device would publish some real time data (e.g. a temperature from a sensor) and an application would subscribe to a topic to receive the temperature values as they are published by the sensor. Having said that, would you consider to make a plan to support MQTT in HTTP Toolkit?

pimterry commented 1 year ago

Having said that, would you consider to make a plan to support MQTT in HTTP Toolkit?

Absolutely, I'd be happy to have it supported! That said, it's quite a bit of work, and the todo list is already very long.

If you're interested in this, pull requests are very welcome and do :+1: on this issue to vote for it.

If you'd like to help with some PRs to move this forward, the first step is to add support to detect MQTT in httpolyglot which looks at the first bytes of a connection to work out which protocol it is (currently handling TLS, HTTP/1 & no-negotiation HTTP/2 all on the same port). I'm not sure what the initial packet of an MQTT connection looks like, but researching and detecting that would all us to independently handle those.

Once that's working, the next step is building a plugin for Mockttp (which uses Httpolyglot to handle HTTP, and provides a base supporting plugins for other protocols) so we can integrate MQTT into the existing HTTP-based interception framework. MockRTC is an example of this for WebRTC, although the plugin framework would probably need a little tweaking for this case.

That's the main hard bit. When that's done, the rest of the work becomes clearer and easier: the new library (let's call it 'MockQTT') can announce events for new connections and messages in each direction (exactly as Mockttp does for HTTP), the UI model would subscribe to those (as it does for HTTP) to collect all the MQTT data, and then we'd need UI components (mainly just reusing the WebSockets UI I expect) to show the connection and the stream of messages within it.

If you're interested in this, feel free to look into that and open issues on the relevant repos if you have any questions. If you're interested but you don't have time for a PR, please to :+1: on this issue anyway, since that's one of the main ways we track priorities for what to implement next.

jewelsonn commented 2 months ago

Hey This may help you in some way to implement MQTT https://github.com/mautrix/facebook/blob/master/maufbapi/mqtt/otclient.py