Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http): enable http2 support #7931

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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())

Expand Down
4 changes: 4 additions & 0 deletions x/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ 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
go startListen(tls.NewListener(httpsRule, tlsConf))
}
}

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,
Expand Down
Loading