Hi all.
My plugin converts XML response from API to JSON.
But now I want to add one improvement: I need to convert XML to JSON only if Accept: application/json is set in the request.
So, the question is: how I can get access to request headers inside responseModifier function?
Some parts of my code:
func (r registerer) RegisterModifiers(f func(
name string,
factoryFunc func(map[string]interface{}) func(interface{}) (interface{}, error),
appliesToRequest bool,
appliesToResponse bool,
)) {
f(string(r)+"-request", r.requestModifier, true, false)
f(string(r)+"-response", r.responseModifier, false, true)
fmt.Println(string(r), "registered!!!")
}
-------------
func (r registerer) requestModifier(
cfg map[string]interface{},
) func(interface{}) (interface{}, error) {
return func(input interface{}) (interface{}, error) {
func (r registerer) responseModifier(
cfg map[string]interface{},
) func(interface{}) (interface{}, error) {
return func(input interface{}) (interface{}, error) {
// need logic to check request headers
if !hasAcceptHeder {
return input, nil
}
modifiedResp := ......
return modifiedResp, nil
}
}