I would like to pass to my upstream only Coffee cookie with valuepresent, thus removing cookies Chocolate, Vanilia and Milk.
I was thinking to use http.rewrite, but it does not have condexists to express it:
rewrite {
if {~Chocolate} exists
if {~Vanilia} is not empty # maybe this is possible?
if {~Milk} exists
if_op or
to /remove_not_needed_cookies{url}
}
proxy /remove_not_needed_cookies {
without /remove_not_needed_cookies
# Now what?
# header_upstream Cookie some_result_of_http_rewrite?
# stuck....
}
So it blocked me.
So, if there would be cookie_upstream and cookie_downstream directives in http.proxy this would automatically solve my issue, I could have Caddyfile like:
You can crudely manipulate cookies via the Cookie header… Unfortunately, though, arbitrary placeholder string manipulation isn’t easy at all.
To determine existence of a cookie, you can test against an empty string "":
rewrite {
if_op or
if {~Chocolate} not ""
if {~Vanilia} not ""
if {~Milk} not ""
to /remove_not_needed_cookies{uri}
}
You could take the sledgehammer approach and overwrite the Cookie header entirely:
proxy /remove_not_needed_cookies {
without /remove_not_needed_cookies
header_upstream Cookie "Coffee={~Coffee}"
}
This PR for regex manipulation of proxied headers would make this much easier (you could simply replace instances of those three cookies with nothing). You might go voice your support there - the proposed changes are currently awaiting a review by a Caddy contributor.