This question already has an answer here:
- How to set headers in http get request? 4 answers
In golang, it seems no hook methods exist for http.client
, so I'm wondering how can I add extra headers like trace-id: xxx
in framework.
Ideal code is like below:
// this func add a hook method to http-client to rewrite header
client := buildWithRewriteHeaderHook()
//customRequest has no `trace-id`
client.Do(customRequest)
// remote server get trace-id from http headers
...
PS: I know how to add headers to a request by 'req.setHeader()', and in my opinion it's not a duplicate question to this one. How to set headers in http get request?
</div>