zap icon indicating copy to clipboard operation
zap copied to clipboard

Support multiple http listeners and udata

Open tadejg opened this issue 3 months ago • 7 comments

Zap's HttpListener is currently a singleton as indicated by the the_one_and_only_listener field. I wonder what the reasoning behind this decision was - I think it would be useful to support multiple listener instances, if possible. From what I can tell, facil.io already supports such use-cases. To make this work, we'd also need to use facil.io's per-connection udata to allow distinguishing between different instances. Btw, the current listener already accepts udata, however it leaves it unused (it's not passed to facil.io nor exposed in any other way).

If there's no argument against it, I'd be happy to implement this.

tadejg avatar Sep 17 '25 11:09 tadejg

You are correct. The reason: I didn't bother to cast around a udata for more 'exotic' use cases, and so far have never needed more than the_one_and_only_listener. The file is short and simple, so I saw it, like most of Zap, as more of a get-you/myself-started-quickly example-ish implementation. It was super easy to put together and move on.

Happy to accept your contribution!

renerocksai avatar Sep 17 '25 12:09 renerocksai

BTW, the same goes for the .startsWith() routing. It started as a quick-first implementation and then I grew to love it.

renerocksai avatar Sep 17 '25 12:09 renerocksai

great, I'll prepare a PR

tadejg avatar Sep 17 '25 12:09 tadejg

@renerocksai PR #182 is ready to be merged. I only updated HttpListener as that's what I need at the moment, but I may submit PRs for the other listeners in the future, when I have more time.

tadejg avatar Sep 17 '25 17:09 tadejg

Btw there aren't any breaking changes. From the user perspective, everything works as it did before, you can just create multiple instances and udata is actually populated into the request struct.

All tests pass and I've validated the functionality in my own project

tadejg avatar Sep 17 '25 17:09 tadejg

@renerocksai what's the ETA on this getting merged?

tadejg avatar Sep 23 '25 09:09 tadejg

@renerocksai ?

tadejg avatar Oct 05 '25 12:10 tadejg