Modify Header Transform Rules Set Cookie from Query Path

Hi,

How do I use fields like http.request.uri.path in the header value response for the Page Transform rules?

I am trying to set a new cookie when a query string exists. Here are the basic rules I am trying to do:

If page requests match
(http.request.uri.query contains "refmid=")

Then
Add: Set-Cookie header with the value of refmid=concat(http.request.uri.path)

The http.request.uri.path I cannot get to be set with the refmid value from the query string. I have tried all of the values for http.request etc etc with and without concat.

Examples seem to just have http.request.uri.path with no problems? Create an HTTP request header modification rule in the dashboard ¡ Cloudflare Rules docs

Also, how do I get the expired time etc automatically for the set cookie response? Is that available too?

Thank you for any help!!

Hey there!

Sorry to hear you’re facing trouble with setting a response header to include the request path.

When using fields such as http.request.uri.path, you need to set it as a Dynamic header, like this, and concat within the parentheses:

The expires portion of the cookie is part of the text string set by the server. That would most likely require a worker to parse through response headers to get the expires string you’d want to include in a custom response header.

2 Likes

Thanks for the concat example!

I am trying to avoid using a worker for such a simple request…

is there no way to also set the date information in the response using concat or something similar?

Set-Dynamic: Set-Cookie redmid=concat(“refmid=”, http,request.uri.path); Expires=concat( ?? ); path=/; secure;

Thanks again!

Edit: Currently looking at field cf.tls_client_auth.cert_not_after I also don’t need the uri.path I need the URI parameter (is that not possible? Argh).

Here’s a rule for ‘BUSINESS USERS’

regex_replace(http.request.uri.query,“(&?(utm_source|utm_medium|utm_campaign|fbclid|fb_action_ids|fb_action_types|fb_source)=[a-zA-Z0-9_]+)*”,“”)

– if there is a better way to go about this, please let me know. I basically just need to add a cookie to start tracking requests while using Cloudflare Page Caching Rules so I can track while the page is serving a cached version.

1 Like

is there no way to also set the date information in the response using concat or something similar?

Dynamic transforms can’t perform calculations or other complex manipulations.

You wouldn’t have to go with a full-blown worker. You can use a Snippet like this:

And work in url.searchParams instead of their group variable.

2 Likes

This topic was automatically closed after 15 days. New replies are no longer allowed.