Adding SPDY to RunTLS

This commit is contained in:
itsmontoya 2015-06-15 15:27:08 -07:00
parent d6425f1692
commit cf595236de

21
gin.go
View File

@ -5,12 +5,16 @@
package gin package gin
import ( import (
"crypto/tls"
"crypto/x509"
"html/template" "html/template"
"net" "net"
"net/http" "net/http"
"os" "os"
"sync" "sync"
"time"
"github.com/bradfitz/http2"
"github.com/gin-gonic/gin/render" "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. // 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) // It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
// Note: this method will block the calling goroutine undefinitelly unless an error happens. // 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) debugPrint("Listening and serving HTTPS on %s\n", addr)
defer func() { debugPrintError(err) }() 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 return
} }