HTTP timeout per handler

94 views
Skip to first unread message

Santiago Corredoira

unread,
Sep 30, 2019, 11:24:45 AM9/30/19
to golang-nuts
Using the http package, timeouts are defined per server. Is there any way of changing it for a specific handler? Imagine a long download from a loged user or a websocket but also be protected against clients that don't close connections and fload the server.

Santiago Corredoira

unread,
Oct 1, 2019, 1:27:42 AM10/1/19
to Nitin Sanghi, golang-nuts
Hi Nitin, but how about making the timeout longer thant the default? For example having a general write timeout of 1 minute but allowing a certain user to download a large file for 30 min.

El mar., 1 oct. 2019 a las 6:31, Nitin Sanghi (<er.niti...@gmail.com>) escribió:
Santiago, you can use context to cancel the request after the certain time you like. 
	ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel()  // releases

On Mon, Sep 30, 2019, 8:54 PM Santiago Corredoira <scorr...@gmail.com> wrote:
Using the http package, timeouts are defined per server. Is there any way of changing it for a specific handler? Imagine a long download from a loged user or a websocket but also be protected against clients that don't close connections and fload the server.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1622fd96-3758-4066-9428-220b5887ddd5%40googlegroups.com.

Nitin Sanghi

unread,
Oct 1, 2019, 9:36:23 AM10/1/19
to Santiago Corredoira, golang-nuts
Santiago, you can use context to cancel the request after the certain time you like. 
	ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel()  // releases

On Mon, Sep 30, 2019, 8:54 PM Santiago Corredoira <scorr...@gmail.com> wrote:
Using the http package, timeouts are defined per server. Is there any way of changing it for a specific handler? Imagine a long download from a loged user or a websocket but also be protected against clients that don't close connections and fload the server.

--

Nitin Sanghi

unread,
Oct 1, 2019, 9:38:58 AM10/1/19
to Santiago Corredoira, golang-nuts
Yes you can do by check size of file or whatever payload you are receiving. You can make run time decision for time
Reply all
Reply to author
Forward
0 new messages