Is there a way to limit number or requests on a KeepAlive connection on net/http server?

579 views
Skip to first unread message

zohaib...@doordash.com

unread,
Jan 13, 2020, 2:00:10 AM1/13/20
to golang-nuts
Hey folks,

 I've been digging around for a while but could not find anything; is there something with builtin HTTP server that I can do to limit the maximum number of requests allowed with KeepAlive connection? I found fast http provides an option MaxRequestsPerConn to do so, https://github.com/valyala/fasthttp/blob/59b28fe0e54664073ac4e422511ca8af718b26b0/server.go#L233-L239 is there something out of the box too? If not I really want to stick to stock net/http package; is there a quick cheap way to do that?

Tamás Gulácsi

unread,
Jan 13, 2020, 2:14:11 AM1/13/20
to golang-nuts
Use Server.ConnState to count idle connections, and close them as you wish.

hao dong

unread,
Jan 15, 2020, 4:53:38 AM1/15/20
to golang-nuts
I don't think you can limit the number of requests by the MaxRequestsPerConn of fasthttp, because the Conn in this func is new struct created by fasthttp which stores in pool. Real client connections will be send to channels which be processed by these Conns.

For @ Tamás , Server.ConnState applies to net connections, not request on the keep-live connection.
Reply all
Reply to author
Forward
0 new messages