From b700d425a40108ebda1d8da4274674e6b06ce102 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Apr 2020 01:37:15 +0300 Subject: [PATCH] api/handler/rpc: improvements and fixes (#1535) * api/handler/rpc: fix empty body case * api/handler/rpc: copy all request headers to metadata Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index d9ff31ad..16e34d0e 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "net/textproto" "strconv" "strings" @@ -119,6 +120,13 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // fill contex with http headers md["Host"] = r.Host + md["Method"] = r.Method + // get canonical headers + for k, _ := range r.Header { + // may be need to get all values for key like r.Header.Values() provide in go 1.14 + md[textproto.CanonicalMIMEHeaderKey(k)] = r.Header.Get(k) + } + // merge context with overwrite cx = metadata.MergeContext(cx, md, true) @@ -384,8 +392,6 @@ func requestPayload(r *http.Request) ([]byte, error) { } if b := buf.Bytes(); len(b) > 0 { bodybuf = b - } else { - return []byte{}, nil } if bodydst == "" || bodydst == "*" { if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil {