-
Notifications
You must be signed in to change notification settings - Fork 372
filters/builtin: drop specified header value #3457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ package builtin | |
|
||
import ( | ||
"fmt" | ||
"net/textproto" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/zalando/skipper/eskip" | ||
|
@@ -47,7 +49,7 @@ type headerFilter struct { | |
func headerFilterConfig(typ headerType, config []interface{}) (string, string, *eskip.Template, error) { | ||
switch typ { | ||
case dropRequestHeader, dropResponseHeader: | ||
if len(config) != 1 { | ||
if len(config) < 1 || len(config) > 2 { | ||
return "", "", nil, filters.ErrInvalidFilterParameters | ||
} | ||
default: | ||
|
@@ -281,7 +283,12 @@ func (f *headerFilter) Request(ctx filters.FilterContext) { | |
ctx.SetOutgoingHost(f.value) | ||
} | ||
case dropRequestHeader: | ||
header.Del(f.key) | ||
if f.value == "" { | ||
header.Del(f.key) | ||
} else { | ||
k := textproto.CanonicalMIMEHeaderKey(f.key) | ||
header[k] = slices.DeleteFunc(header[k], func(v string) bool { return v == f.value }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think value should also be case insensitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea was to have a low-level primitive to drop a specific value. To support regexp we may consider changing modRequestHeader such that it deletes the matching header if "the replacement (string)" parameter is empty (or absent) or maybe add a whole new filter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add another filter dropRequestHeaderRegexp maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I'd wait until we have a usecase for regexp value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could a third boolean parameter to enable case-insensitive comparison be an alternative to regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be done like that of course but lets wait for the usecase. I initially considered to add a new filter These header filters are basic primitives and building blocks and I think we should keep them simple. For higher-level or interesting logic we can always add new filters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Indeed, thanks, a new dropRequestHeaderRegexp would be better because exact value match is a very simple regexp ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This could be achieved by regexp flags (e.g. |
||
} | ||
case setContextRequestHeader: | ||
valueFromContext(ctx, f.key, f.value, true, header.Set) | ||
case appendContextRequestHeader: | ||
|
@@ -313,7 +320,12 @@ func (f *headerFilter) Response(ctx filters.FilterContext) { | |
case depResponseHeader: | ||
header.Add(f.key, f.value) | ||
case dropResponseHeader: | ||
header.Del(f.key) | ||
if f.value == "" { | ||
header.Del(f.key) | ||
} else { | ||
k := textproto.CanonicalMIMEHeaderKey(f.key) | ||
header[k] = slices.DeleteFunc(header[k], func(v string) bool { return v == f.value }) | ||
} | ||
case setContextResponseHeader: | ||
valueFromContext(ctx, f.key, f.value, false, header.Set) | ||
case appendContextResponseHeader: | ||
|
Uh oh!
There was an error while loading. Please reload this page.