-
Notifications
You must be signed in to change notification settings - Fork 112
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
[Question] possible without tls #22
Comments
And to answer my question this is due to the http.Server upgrading to http2 |
That seems to be the case for http directly hitting the gateway, but I also get the same issue when using a grpc client which should already be http2. |
The same problem, anyone can explain how to fix it in other ways? |
Same question, is there any way to run grpc server and grpc gateway in a port without tls? |
Hi, I also had to get it working without TLS, so I adapted the code. You can find my version here: https://github.com/Stoakes/grpc-gateway-example |
So youre version use cmux apparently and set back regular HTTP connection to use HTTP 1 for non-gRPC connections. I've dig up a little bit by re-creating a small example and what I found is that in the After that, I tried to run a basic basic gRPC example starting from a Any ideas ? |
Just for reference everything is explained here grpc/grpc-go#555 In short, it's not directly possible for now and there's a few options described in this post (including cmux's solution like @Stoakes ): https://medium.com/@thatcher/why-choose-between-grpc-and-rest-bc0d351f2f84 |
I used the details from grpc/grpc-go#555 for a workaround: import (
"context"
"net/http"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
pb "github.com/philips/grpc-gateway-example/echopb"
)
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
return h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
grpcServer.ServeHTTP(w, r)
} else {
otherHandler.ServeHTTP(w, r)
}
}), &http2.Server{})
}
func StartServer() {
grpcServer := grpc.NewServer()
pb.RegisterEchoServiceServer(grpcServer, newServer())
mux := http.NewServeMux()
gwmux := runtime.NewServeMux()
ctx := context.Background()
dopts := []grpc.DialOption{grpc.WithInsecure()}
err = pb.RegisterEchoServiceHandlerFromEndpoint(ctx, gwmux, "localhost:8020", dopts)
http.ListenAndServe(":8020", grpcHandlerFunc(grpcServer, mux))
} |
@adamcohen |
- mux := http.NewServeMux()
gwmux := runtime.NewServeMux()
ctx := context.Background()
dopts := []grpc.DialOption{grpc.WithInsecure()}
err = pb.RegisterEchoServiceHandlerFromEndpoint(ctx, gwmux, "localhost:8020", dopts)
- http.ListenAndServe(":8020", grpcHandlerFunc(grpcServer, mux))
+ http.ListenAndServe(":8020", grpcHandlerFunc(grpcServer, gwmux)) Hey @adamcohen, as per my example above, why do we need the |
@kadenlnelson possibly - I think there was a reason why I needed the separate |
I think the mux is used for serving the swagger ui |
Tried using this with grpc gateway, but paths that take in a body seem to be losing the request body somewhere downstream. Anyone else experiencing this? |
Works fine for me. I have tried a POST endpoint with payload in the body. |
I'm attempting to terminate tls before hitting the grpc/rest gateway so I disabled the TLS certs in the code base and turned on grpc.WithInsecure, but I always end up with
{"error":"transport is closing","code":14}%
The text was updated successfully, but these errors were encountered: