Making decisions based on HTTP headers
24 Feb 26
Every time a browser requests a webpage, an invisible conversation occurs in just milliseconds. In this exchange, the client and server do more than just swap content like HTML or images; they also trade a set of critical instructions: HTTP headers.
These headers determine how traffic behaves, how cache is stored, and how user privacy is protected. Processing them at the edge allows you to solve complex infrastructure challenges without touching a single line of code on your origin servers. In this post, we explore two critical functions you must master to move beyond using your CDN as a simple cache and start using it as an intelligent layer for cybersecurity and performance: dynamic backend routing and exclusive access control.
What if you could direct your users to different servers without them noticing and without changing the URL? This is the magic of changing the backend based on headers.
A very common use case is geo-routing. This is incredibly useful, for example, if you run an international newspaper and want to ensure a user in Miami doesn’t have to cross the Atlantic to fetch content from a server in Madrid.
With just a few lines of VCL, you can ensure that American users communicate with an American server, cutting load times (TTFB – Time to First Byte) by more than half. At Transparent Edge, this can be implemented using the geo_country_code header:
sub vcl_recv{
# Default backend
set req.backend_hint = c82_tcdnes.backend();
# Changing backend for Spanish users
if (req.http.geo_country_code ~ "ES") {
set req.backend_hint = c82_tcdnes.backend();
}
# Changing backend for American users
if (req.http.geo_country_code ~ "US") {
set req.backend_hint = c82_tcdnus.backend();
}
}
X-Beta-User: true—to a server running the new version of your website, while the rest of the world continues to see the stable version.User-Agent) to an API-optimized backend, while directing desktop traffic to one optimized for web rendering.Sometimes, you don’t want your content to be accessible to everyone, or you want to ensure that only specific applications can consume your resources. In cybersecurity terms, this is what we call edge token validation.
By implementing an auth-tcdn header check, you can block unauthorized requests directly at the edge. This not only protects your data but also saves bandwidth and CPU on your servers, as malicious traffic never even reaches them.
sub vcl_recv{
if (req.http.auth-tcdn != "e37be3f5e06e263445654c0d6ba0e123") {
call deny_request;
}
}
Referer header at the edge.Mastering HTTP headers is the first step toward optimizing your CDN usage. Whether you are testing new features risk-free or shielding access to your data, the flexibility offered by languages like VCL at Transparent Edge is your greatest ally.
Do you need to implement a custom backend logic? Our technical team can help you design the perfect VCL rule for your specific use case.