mwitkow / grpc-proxy

gRPC proxy is a Go reverse proxy that allows for rich routing of gRPC calls with minimum overhead.
Apache License 2.0
962 stars 210 forks source link

`failed to unmarshal, message is *proxy.Frame, want proto.Message` #74

Closed Philmod closed 10 months ago

Philmod commented 10 months ago

Hi!

When trying to use this proxy[0], I'm getting the following error: failed to unmarshal the received message: failed to unmarshal, message is *proxy.Frame, want proto.Message

Some more info in case that helps:

What could I do to fix?

Thank you so much, Philmod

[0]

director := func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {
    md, _ := metadata.FromIncomingContext(ctx)
    outCtx := metadata.NewOutgoingContext(ctx, md.Copy())
    if err := CheckBearerToken(ctx); err != nil {
        return outCtx, nil, grpc.Errorf(codes.PermissionDenied, "unauthorized access: %v", err)
    }
    return outCtx, backendConn, nil
}

server := grpc.NewServer(grpc.UnknownServiceHandler(proxy.TransparentHandler(director)))
Philmod commented 10 months ago

I was able to fix it using a new codec:

func EncodingCodec() encoding.Codec {
    return &rawCodec{&protoCodec{}}
}