From b3cbbe2228052a18e01f143b44afb2e5bf42e100 Mon Sep 17 00:00:00 2001 From: dingjun Date: Mon, 31 May 2021 13:17:12 +0800 Subject: [PATCH] add CallWithHeader --- http_transport.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/http_transport.go b/http_transport.go index 396a680..37f756c 100644 --- a/http_transport.go +++ b/http_transport.go @@ -47,8 +47,12 @@ func (h *HTTPTransport) nextID() uint64 { return h.nextid } -// Call call a remote method func (h *HTTPTransport) Call(method string, args interface{}, reply interface{}) error { + return h.CallWithHeader(method, args, reply, nil) +} + +// Call call a remote method +func (h *HTTPTransport) CallWithHeader(method string, args interface{}, reply interface{}, header http.Header) error { if args == nil { args = []string{} } @@ -57,7 +61,7 @@ func (h *HTTPTransport) Call(method string, args interface{}, reply interface{}) Version: "2.0", Method: method, Params: args, - ID: fmt.Sprintf("%d", h.nextID()), + ID: h.nextID(), } data, err := json.Marshal(r) @@ -74,6 +78,14 @@ func (h *HTTPTransport) Call(method string, args interface{}, reply interface{}) return err } + if header != nil { + for k, v := range header { + for _, v1 := range v { + req.Header.Add(k, v1) + } + } + } + req.Header.Set("Content-Type", "application/json") resp, err := h.Client.Do(req)