From cf595236de0727415f319928728799957cef612a Mon Sep 17 00:00:00 2001 From: itsmontoya Date: Mon, 15 Jun 2015 15:27:08 -0700 Subject: [PATCH] Adding SPDY to RunTLS --- gin.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index 8130b88f..dadf79b7 100644 --- a/gin.go +++ b/gin.go @@ -5,12 +5,16 @@ package gin import ( + "crypto/tls" + "crypto/x509" "html/template" "net" "net/http" "os" "sync" + "time" + "github.com/bradfitz/http2" "github.com/gin-gonic/gin/render" ) @@ -195,11 +199,24 @@ func (engine *Engine) Run(addr string) (err error) { // The router is attached to a http.Server and starts listening and serving HTTPS requests. // It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router) // Note: this method will block the calling goroutine undefinitelly unless an error happens. -func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err error) { +func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error) { debugPrint("Listening and serving HTTPS on %s\n", addr) defer func() { debugPrintError(err) }() - err = http.ListenAndServeTLS(addr, certFile, keyFile, engine) + cfg := tls.Config{InsecureSkipVerify: false, RootCAs: x509.NewCertPool()} + cfg.BuildNameToCertificate() + + srv := http.Server{ + Addr: addr, + Handler: engine, + ReadTimeout: 5 * time.Second, + WriteTimeout: 5 * time.Second, + MaxHeaderBytes: 16384, + TLSConfig: &cfg, + } + + http2.ConfigureServer(&srv, &http2.Server{}) + err = srv.ListenAndServeTLS(certFile, keyFile) return }