valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.73k stars 1.75k forks source link

question: Add user level value to connection? #1699

Open stevedw opened 8 months ago

stevedw commented 8 months ago

Would it be possible to add an exposed user level value (something like a uint64) to the underlying connection on the request context.

This would make adding stuff like rate limit much easier without having to maintain another book keeping data structure keyed by conn id and then having to deal with connection timeouts and book-keeping etc in the user code.

Ideally it would be useful to have it as a direct value so the caller can decide on atomic or not.

Obviously, one could do it with user level attributes, but often the dos spam type stuff is just brute forcing at a conn level and rates are useful to apply at this level prior to identifying a user identity.

erikdubbelboer commented 8 months ago

A pull request would be welcome!