func AddHeaderMutation()

in callouts/go/extproc/pkg/utils/callout_tools.go [43:77]


func AddHeaderMutation(add []struct{ Key, Value string }, remove []string, clearRouteCache bool, appendAction *base.HeaderValueOption_HeaderAppendAction) *extproc.HeadersResponse {
	headerMutation := &extproc.HeaderMutation{}

	if add != nil {
		for _, kv := range add {
			headerValueOption := &base.HeaderValueOption{
				Header: &base.HeaderValue{
					Key:      kv.Key,
					RawValue: []byte(kv.Value),
				},
			}
			if appendAction != nil {
				headerValueOption.AppendAction = *appendAction
			}
			headerMutation.SetHeaders = append(headerMutation.SetHeaders, headerValueOption)
		}
	}

	if remove != nil {
		headerMutation.RemoveHeaders = append(headerMutation.RemoveHeaders, remove...)
	}

	headersResponse := &extproc.HeadersResponse{
		Response: &extproc.CommonResponse{
			HeaderMutation:  headerMutation,
			ClearRouteCache: clearRouteCache,
		},
	}

	if clearRouteCache {
		headersResponse.Response.ClearRouteCache = true
	}

	return headersResponse
}