I'm moving a webapp from .NET to Java platform and I have to deal with a legacy malformed cookie. I need to read a cookie with comma-separated value, and as explained in this other question it's not valid. When I try to read from HttpServletRequest it gives me just the first value from the comma separated list.
My last approach to solve this problem is to modify the cookie value from an apache server using mod_rewrite.
As I am an newbie with apache configuration I didn't get a correct way to replace ALL the commas with another character.
My best approach is to replace 9 commas, or 8 commas... or 1 comma this way:
RewriteEngine On
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5|%6|%7|%8|%9|%10:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5|%6|%7|%8|%9:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5|%6|%7|%8:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5|%6|%7:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5|%6:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4|%5:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3|%4:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2|%3:dev.server.intranet:43200]
RewriteCond %{HTTP_COOKIE} COOKIE_NAME=(.*),(.*)
RewriteRule ^(.*)$ - [CO=COOKIE_NAME:%1|%2:dev.server.intranet:43200]
I think it's ugly and incomplete because if the comma-separated list is longer than 10 values it will need an extra call to be completely fixed.
I've been trying the Next [N] flag to iterate until no commas left, but it didn't worked.
I've been looking for mod_headers but I think that I'm in the same iteration problem.
Finally I found the solution:
RequestHeader edit* Cookie "(,)" "|"
With this ALL commas in all the cookies will be replaced by a '|' character.