JavaScript Examples - Adding a response header
Explore how geo-location data in Edge Computing enables dynamic web application responses using Functions and JavaScript.
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
The function listens for the firewall event with addEventListener, wrapping the asynchronous handler in event.waitUntil() so processing completes before the event ends. It 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. Finally, event.continue() lets the request proceed normally so it reaches its destination instead of being blocked.