Add a response header
Add a response header based on the visitor's country, with a function that runs on a firewall and reads GeoIP metadata.
Add a response header based on the visitor’s country, resolved from GeoIP data on Azion’s global network. Use this pattern in a firewall function to tag or flag traffic from specific regions, for example to drive country-specific logic downstream without blocking the request.
How it works
This code runs as a firewall handler, so it executes in a firewall and not in the application request path. It registers the handler with addEventListener("firewall", ...) and wraps the asynchronous work in event.waitUntil(), so processing completes before the event ends. Refer to Functions for Firewall for the full set of actions a firewall handler can call.
The handler reads the country code from event.request.metadata["geoip_country_code"], and when the visitor is from Brazil it calls event.addResponseHeader("test", "true") to attach a custom header to the response. It ends with event.continue(), which lets the request proceed to its destination instead of being blocked.