From 92c875f103ba74e6c024ef6558dbbf69a4c31aa3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 11 Feb 2020 11:27:16 +0000 Subject: [PATCH] parse url encoded form in rpc handler (#1183) * parse url encoded form in rpc handler * Remove comment --- rpc.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rpc.go b/rpc.go index 76e60dc..daf601a 100644 --- a/rpc.go +++ b/rpc.go @@ -202,8 +202,9 @@ func hasCodec(ct string, codecs []string) bool { func requestPayload(r *http.Request) ([]byte, error) { // we have to decode json-rpc and proto-rpc because we suck // well actually because there's no proxy codec right now - switch r.Header.Get("Content-Type") { - case "application/json-rpc": + ct := r.Header.Get("Content-Type") + switch { + case strings.Contains(ct, "application/json-rpc"): msg := codec.Message{ Type: codec.Request, Header: make(map[string]string), @@ -217,7 +218,7 @@ func requestPayload(r *http.Request) ([]byte, error) { return nil, err } return ([]byte)(raw), nil - case "application/proto-rpc", "application/octet-stream": + case strings.Contains(ct, "application/proto-rpc"), strings.Contains(ct, "application/octet-stream"): msg := codec.Message{ Type: codec.Request, Header: make(map[string]string), @@ -232,6 +233,19 @@ func requestPayload(r *http.Request) ([]byte, error) { } b, _ := raw.Marshal() return b, nil + case strings.Contains(ct, "application/www-x-form-urlencoded"): + r.ParseForm() + + // generate a new set of values from the form + vals := make(map[string]string) + for k, v := range r.Form { + vals[k] = strings.Join(v, ",") + } + + // marshal + b, _ := json.Marshal(vals) + return b, nil + // TODO: application/grpc } // otherwise as per usual