I'd like to modify a Cookie RequestHeader using a regex to prevent sending too many cookies to the server, because the server wil simply drop the request on too large headers. However, I don't want to drop all the cookies, because I still niet the 'authorization' cookie. That being said, not all request contain the 'authorization' cookie.
# example cookie A:
foo=bar;authorization=jwt;more=bla
#example cookie B:
foo=bar;more=bla
Using zalando's skipper filter, I can modify the request header like so:
zalando.org/skipper-filter: modRequestHeader("Cookie", "^(.*)(authorization=.[^;]+;)(.*)$", "$2")
This will work in case of A, but not in case of B, as then I'll get ALL the cookies instead of NONE.
So how do I modify the regex to fix it to work in both cases?
EDIT: Thanks @Wiktor
I ended up with this working solution, as a single cookie didn't need a trailing semicolon:
zalando.org/skipper-filter: modRequestHeader("Cookie", "^(?:(.*)(authorization=[^;]+)(.*)|.+)$", "$2")