api/handler/rpc: fix corner cases

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-11-10 11:00:06 +03:00
parent fa9ef1c816
commit e3f235acc1
3 changed files with 8 additions and 4 deletions

View File

@ -250,7 +250,9 @@ func requestPayload(r *http.Request) ([]byte, error) {
} }
return raw.Marshal() return raw.Marshal()
case strings.Contains(ct, "application/www-x-form-urlencoded"): 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 // generate a new set of values from the form
vals := make(map[string]string, len(r.Form)) vals := make(map[string]string, len(r.Form))

View File

@ -2,12 +2,12 @@ package rpc
import ( import (
"bytes" "bytes"
"encoding/json"
"net/http" "net/http"
"testing" "testing"
"github.com/golang/protobuf/proto"
go_api "github.com/unistack-org/micro/v3/api/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) { func TestRequestPayloadFromRequest(t *testing.T) {
@ -22,7 +22,7 @@ func TestRequestPayloadFromRequest(t *testing.T) {
t.Fatal("Failed to marshal proto", err) t.Fatal("Failed to marshal proto", err)
} }
jsonBytes, err := json.Marshal(protoEvent) jsonBytes, err := jsonpb.Marshal(&protoEvent)
if err != nil { if err != nil {
t.Fatal("Failed to marshal proto to JSON ", err) t.Fatal("Failed to marshal proto to JSON ", err)
} }

View File

@ -44,6 +44,8 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
case "binary": case "binary":
hdr["Sec-WebSocket-Protocol"] = []string{"binary"} hdr["Sec-WebSocket-Protocol"] = []string{"binary"}
op = ws.OpBinary op = ws.OpBinary
default:
op = ws.OpBinary
} }
} }
} }