-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Issue Details
I wrote a simple string manipulation plugin to alter placeholders with lower/upper case by appending a .lower or .upper suffix. It works by adding a custom Replacer provider mapping function. Testing showed it worked fine with static placeholders, however, it wasn't triggering on dynamic placeholders such as http.request.header.*, http.request.uri.query.*, etc. After further debugging, the issue stems from the implementation of dynamic placeholders in the addHTTPVarsToReplacer function. The dynamic placeholders are replaced whether it finds a set key or not (returning empty string if not found). However, this means that custom providers further down the chain which may want to hook into a dynamic placeholder will never be called.
ie. http.request.header.x-custom-header.upper will always be stopped in the addHTTPVarsToReplacer provider chain and return empty even though it doesn't exist.
I propose that all Replacer logic handling dynamic placeholders return false if there isn't a key match, thereby allowing other providers to apply their own logic. ie.
// request header fields
if strings.HasPrefix(key, reqHeaderReplPrefix) {
field := key[len(reqHeaderReplPrefix):]
vals := req.Header[textproto.CanonicalMIMEHeaderKey(field)]
// always return true, since the header field might
// be present only in some requests
return strings.Join(vals, ","), true
}
becomes:
// request header fields
if strings.HasPrefix(key, reqHeaderReplPrefix) {
field := key[len(reqHeaderReplPrefix):]
vals := req.Header[textproto.CanonicalMIMEHeaderKey(field)]
if len(vals) == 0 {
return "", false
}
return strings.Join(vals, ","), true
}
Based on my testing I see no adverse effects and resolves the chaining issue, but rather than adding a pull request I thought it's best to check what the feedback on a change like this would be, and whether it's something that would be accepted.
Thanks.
Assistance Disclosure
AI not used
If AI was used, describe the extent to which it was used.
No response