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

make /api/ h2c compatible #590

Merged
merged 1 commit into from
Jul 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/improbable-eng/grpc-web v0.15.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
golang.org/x/net v0.9.0
golang.org/x/sys v0.10.0
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
Expand Down Expand Up @@ -45,7 +46,6 @@ require (
github.com/rs/cors v1.7.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/pflag v1.0.6-0.20200504143853-81378bbcd8a1 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.7.0 // indirect
Expand Down
5 changes: 4 additions & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
gops "github.com/google/gops/agent"
"github.com/improbable-eng/grpc-web/go/grpcweb"
"github.com/sirupsen/logrus"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"golang.org/x/sys/unix"
"google.golang.org/grpc"

Expand Down Expand Up @@ -55,6 +57,7 @@ func runServer(cfg *config.Config) {
req.URL.Path = req.URL.Path[len("/api/"):]
wrappedGrpc.ServeHTTP(resp, req)
})
h2cHandler := h2c.NewHandler(handler, &http2.Server{})

ctx, cancel := signal.NotifyContext(context.Background(), unix.SIGINT, unix.SIGTERM)
defer cancel()
Expand All @@ -63,7 +66,7 @@ func runServer(cfg *config.Config) {

httpSrv := &http.Server{
Addr: addr,
Handler: handler,
Handler: h2cHandler,
BaseContext: func(net.Listener) context.Context {
return ctx
},
Expand Down
240 changes: 240 additions & 0 deletions backend/vendor/golang.org/x/net/http2/h2c/h2c.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ github.com/spf13/pflag
golang.org/x/net/context
golang.org/x/net/http/httpguts
golang.org/x/net/http2
golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/internal/timeseries
Expand Down
Loading