Functions on a firewall
Deny, drop, modify, or answer a request from one firewall handler, using the event actions available to a function on a firewall.
A general-purpose example for functions that run on the firewall, combining several request-handling actions in one handler. Use it as a starting point when you need to inspect incoming headers and metadata and then decide whether to block, drop, modify, or answer a request directly on Azion’s global network. The sample code exemplifies the following capabilities:
event.deny()event.drop()event.addRequestHeader()event.addResponseHeader()event.respondWith()event.continue()
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 runs the asynchronous work inside event.waitUntil(). Refer to Functions for Firewall for the full set of actions a firewall handler can call.
The handler reads several request headers with event.request.headers.get() to drive its decisions. Depending on which header is present, it can call event.deny() to return a 403, event.drop() to close the connection without a response, or event.addRequestHeader() and event.addResponseHeader() to inject custom headers. It also inspects event.request.metadata["remote_addr"] and can short-circuit with event.respondWith(new Response(...)) to serve a custom JSON body. It ends with event.continue(), so any request not already handled proceeds normally.