From 520dc29f89d8af6bdc1a9f9a70dc500274769047 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 9 Jul 2021 12:25:26 +0300 Subject: [PATCH] fixup header filling after making new request Signed-off-by: Vasiliy Tolstov --- http.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/http.go b/http.go index d64bc88..30f847b 100644 --- a/http.go +++ b/http.go @@ -123,23 +123,11 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg } func (h *httpClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error { - header := make(http.Header, 2) - if md, ok := metadata.FromOutgoingContext(ctx); ok { - for k, v := range md { - header.Set(k, v) - } - } - ct := req.ContentType() if len(opts.ContentType) > 0 { ct = opts.ContentType } - // set timeout in nanoseconds - header.Set("Timeout", fmt.Sprintf("%d", opts.RequestTimeout)) - // set the content type for the request - header.Set("Content-Type", ct) - cf, err := h.newCodec(ct) if err != nil { return errors.InternalServerError("go.micro.client", err.Error()) @@ -149,7 +137,16 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request, return err } - hreq.Header = header + if md, ok := metadata.FromOutgoingContext(ctx); ok { + for k, v := range md { + hreq.Header.Set(k, v) + } + } + + // set timeout in nanoseconds + hreq.Header.Set("Timeout", fmt.Sprintf("%d", opts.RequestTimeout)) + // set the content type for the request + hreq.Header.Set("Content-Type", ct) // make the request hrsp, err := h.httpcli.Do(hreq.WithContext(ctx))