daurnimator / lua-http

HTTP Library for Lua. Supports HTTP(S) 1.0, 1.1 and 2.0; client and server.
https://daurnimator.github.io/lua-http/
MIT License
778 stars 80 forks source link

Add server:connections() #173

Open sparked435 opened 3 years ago

sparked435 commented 3 years ago

Adds :connections() method to http.server objects, so that external code can see how many client connections are actively being handled.

A project needed this for statistics and load balancing.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.004%) to 87.785% when pulling aaae4643b02f3e25c7ceb8e892c71a1aa5f6a4c9 on sparked435:master into 47225d081318e65d5d832e2dd99ff0880d56b5c6 on daurnimator:master.

daurnimator commented 3 years ago

The method name :connections() to me suggests an iterator over connections, rather than something that returns a count.

Maybe the existing field .n_connections could just be documented as part of public API?

sparked435 commented 3 years ago

That works fine for me.

I assumed that it was a private field that shouldn't be utilized out of fear breaking encapsulation. If that's not a concern, and n_connections can be assumed to be part of the public API going forward, I've already got everything I need in the existing release. I can amend this to just a documentation change.

I'm also okay with renaming it to something like :connection_count(), or just about anything else, if encapsulation is something to worry about.

sparked435 commented 3 years ago

I'm not particularly concerned about the name. I probably would call it active_connections() but, to your point, that still sounds somewhat like an iterator.

Any of these work for you? number_connections() connection_count() total_connections()