diff --git a/dgraph/cmd/alpha/run.go b/dgraph/cmd/alpha/run.go index ec0d8d672d6..8db5deb0480 100644 --- a/dgraph/cmd/alpha/run.go +++ b/dgraph/cmd/alpha/run.go @@ -41,6 +41,8 @@ import ( "go.opencensus.io/plugin/ocgrpc" otrace "go.opencensus.io/trace" "go.opencensus.io/zpages" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" "golang.org/x/net/trace" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -573,6 +575,7 @@ func setupServer(closer *z.Closer) { baseMux.Handle("/", http.HandlerFunc(homeHandler)) baseMux.Handle("/ui/keywords", http.HandlerFunc(keywordHandler)) + x.H2cHandler = h2c.NewHandler(baseMux, &http2.Server{}) // Initialize the servers. x.ServerCloser.AddRunning(3) go serveGRPC(grpcListener, tlsCfg, x.ServerCloser) diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index 0bd25781fdd..75161c97108 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -34,6 +34,8 @@ import ( "go.opencensus.io/plugin/ocgrpc" otrace "go.opencensus.io/trace" "go.opencensus.io/zpages" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" "golang.org/x/net/trace" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -316,7 +318,6 @@ func run() { tlsCfg, err := x.LoadServerTLSConfig(Zero.Conf) x.Check(err) - go x.StartListenHttpAndHttps(httpListener, tlsCfg, st.zero.closer) baseMux := http.NewServeMux() http.Handle("/", audit.AuditRequestHttp(baseMux)) @@ -333,6 +334,10 @@ func run() { baseMux.HandleFunc("/debug/jemalloc", x.JemallocHandler) zpages.Handle(baseMux, "/debug/z") + x.H2cHandler = h2c.NewHandler(baseMux, &http2.Server{}) + + go x.StartListenHttpAndHttps(httpListener, tlsCfg, st.zero.closer) + // This must be here. It does not work if placed before Grpc init. x.Check(st.node.initAndStartNode()) diff --git a/x/server.go b/x/server.go index 38229128acb..f0e1cf3d219 100644 --- a/x/server.go +++ b/x/server.go @@ -52,6 +52,7 @@ func startServers(m cmux.CMux, tlsConf *tls.Config) { // if tls is enabled, make tls encryption based connections as default if tlsConf != nil { + tlsConf.NextProtos = []string{"h2", "http/1.1"} httpsRule := m.Match(cmux.Any()) // this is chained listener. tls listener will decrypt // the message and send it in plain text to HTTP server @@ -59,8 +60,11 @@ func startServers(m cmux.CMux, tlsConf *tls.Config) { } } +var H2cHandler http.Handler + func startListen(l net.Listener) { srv := &http.Server{ + Handler: H2cHandler, ReadTimeout: 10 * time.Second, WriteTimeout: 600 * time.Second, IdleTimeout: 2 * time.Minute,