diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 127e2dfa..7ddb980d 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -250,7 +250,9 @@ func requestPayload(r *http.Request) ([]byte, error) { } return raw.Marshal() case strings.Contains(ct, "application/www-x-form-urlencoded"): - r.ParseForm() + if err = r.ParseForm(); err != nil { + return nil, err + } // generate a new set of values from the form vals := make(map[string]string, len(r.Form)) diff --git a/api/handler/rpc/rpc_test.go b/api/handler/rpc/rpc_test.go index a375ab3b..15453c44 100644 --- a/api/handler/rpc/rpc_test.go +++ b/api/handler/rpc/rpc_test.go @@ -2,12 +2,12 @@ package rpc import ( "bytes" - "encoding/json" "net/http" "testing" - "github.com/golang/protobuf/proto" go_api "github.com/unistack-org/micro/v3/api/proto" + jsonpb "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" ) func TestRequestPayloadFromRequest(t *testing.T) { @@ -22,7 +22,7 @@ func TestRequestPayloadFromRequest(t *testing.T) { t.Fatal("Failed to marshal proto", err) } - jsonBytes, err := json.Marshal(protoEvent) + jsonBytes, err := jsonpb.Marshal(&protoEvent) if err != nil { t.Fatal("Failed to marshal proto to JSON ", err) } diff --git a/api/handler/rpc/stream.go b/api/handler/rpc/stream.go index 067c890e..e93c46ce 100644 --- a/api/handler/rpc/stream.go +++ b/api/handler/rpc/stream.go @@ -44,6 +44,8 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, case "binary": hdr["Sec-WebSocket-Protocol"] = []string{"binary"} op = ws.OpBinary + default: + op = ws.OpBinary } } }