Skip to content

Commit

Permalink
http2 without tls (h2c)
Browse files Browse the repository at this point in the history
  • Loading branch information
NamanJain8 authored and mangalaman93 committed Oct 18, 2024
1 parent f943dd1 commit 10c852a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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
3 changes: 3 additions & 0 deletions x/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,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,
Expand Down

0 comments on commit 10c852a

Please sign in to comment.