Cloudflare Docs
Rules
Rules
Edit this page on GitHub
Set theme to dark (⇧+D)

Response header modification examples

The following examples illustrate how to perform response header modifications with Transform Rules:

​​ Set an HTTP response header to a static value

The following HTTP response header modification rule sets a header named X-Source to a static value (Cloudflare) in the response:

Text in Expression Editor:

starts_with(http.request.uri.path, "/en/")

Selected operation under Modify response header: Set static

Header name: X-Source

Value: Cloudflare

This rule would overwrite any existing X-Source headers already present in the response.

​​ Set an HTTP response header to the current bot score

The following HTTP response header modification rule sets a header named X-Bot-Score to the current bot score in the response:

Text in Expression Editor:

starts_with(http.request.uri.path, "/en/")

Selected operation under Modify response header: Set dynamic

Header name: X-Bot-Score

Value: to_string(cf.bot_management.score)

This rule would overwrite any existing X-Bot-Score headers already present in the response.

​​ Add an HTTP response header with a static value

The following HTTP response header modification rule adds a header named set-cookie with a static value (cookiename=value) to the response:

Text in Expression Editor:

starts_with(http.request.uri.path, "/en/")

Selected operation under Modify response header: Add

Header name: set-cookie

Value: cookiename=value

This rule would keep any existing set-cookie headers already present in the response.

​​ Remove an HTTP response header

The following HTTP response header modification rule removes the cf-connecting-ip header from the response:

Text in Expression Editor:

starts_with(http.request.uri.path, "/private/")

Selected operation under Modify response header: Remove

Header name: cf-connecting-ip