From e712e7f3b1c81b150efd95de886778458be8073a Mon Sep 17 00:00:00 2001 From: anirut Date: Thu, 1 Sep 2022 00:36:30 +0700 Subject: [PATCH] :zap: add headers option --- transport/http/calloption.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/transport/http/calloption.go b/transport/http/calloption.go index 7b0ed82d1..0b245079a 100644 --- a/transport/http/calloption.go +++ b/transport/http/calloption.go @@ -20,6 +20,7 @@ type callInfo struct { contentType string operation string pathTemplate string + headers map[string]string } // EmptyCallOption does not alter the Call configuration. @@ -55,6 +56,7 @@ func defaultCallInfo(path string) callInfo { contentType: "application/json", operation: path, pathTemplate: path, + headers: make(map[string]string), } } @@ -107,3 +109,20 @@ func (o HeaderCallOption) after(c *callInfo, cs *csAttempt) { *o.header = cs.res.Header } } + +// Headers returns a CallOptions that pass the http request header +// to server . +func Headers(headers map[string]string) CallOption { + return HeadersCallOption{headers: headers} +} + +// HeaderCallOption is http headers that want to set before call the client +type HeadersCallOption struct { + EmptyCallOption + headers map[string]string +} + +func (o HeadersCallOption) before(c *callInfo) error { + c.headers = o.headers + return nil +}