Gin: add support to disabe keepalive

Created on 6 May 2015  ·  3Comments  ·  Source: gin-gonic/gin

If gin would've used http.Server, I could've just done the following:

// s is a http.Server instance
s.SetKeepAlivesEnabled(false)

But gin doesn't allow that. So, how do we accomplish this?

invalid question

Most helpful comment

https://github.com/gin-gonic/gin#custom-http-configuration

    router := gin.Default()

    s := &http.Server{
        Addr:           ":8080",
        Handler:        router, // < here Gin is attached to the HTTP server
    //  ReadTimeout:    10 * time.Second,
    //  WriteTimeout:   10 * time.Second,
    //  MaxHeaderBytes: 1 << 20,
    }
    s.SetKeepAlivesEnabled(false)
    s.ListenAndServe()

Gin (muxer) and the HTTP server work at different layers of abstraction.

All 3 comments

:+1:
could be especially useful for scalable REST servers, so single-request connections don't linger.

https://github.com/gin-gonic/gin#custom-http-configuration

    router := gin.Default()

    s := &http.Server{
        Addr:           ":8080",
        Handler:        router, // < here Gin is attached to the HTTP server
    //  ReadTimeout:    10 * time.Second,
    //  WriteTimeout:   10 * time.Second,
    //  MaxHeaderBytes: 1 << 20,
    }
    s.SetKeepAlivesEnabled(false)
    s.ListenAndServe()

Gin (muxer) and the HTTP server work at different layers of abstraction.

@manucorporat amazing and simple. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

boneq picture boneq  ·  3Comments

gplume picture gplume  ·  3Comments

atifzia picture atifzia  ·  3Comments

ghost picture ghost  ·  3Comments

sofish picture sofish  ·  3Comments