Script
onClientRequest returns a response, the CDN sends it as it is.
onClientResponse does not run, so set every header you need on the rejection
response itself.
Set up
1
Create the script
Create a Middleware script, and paste the code above. See the
quickstart.
2
Add the secret
Add a secret named
ACCESS_TOKEN that holds the token. See
Secrets.3
Publish and link the script
Publish the script, and link it to the Pull Zone that serves the private
content.
4
Enable before cache execution
In the Pull Zone, go to General > Origin, and enable Run script
before cache. If you skip this step,
onClientRequest does not run, and
the CDN serves the content to all clients with no error.MiddlewareScriptId to the script ID, and EdgeScriptExecutionPhase to 2
for before cache execution. The default value, 0, runs the script after the
cache.
Verify
Test against the Pull Zone hostname, not a local server. TheCDN-Cache
response header shows whether the CDN served the response from the cache.
Close other access paths
The script protects only the Pull Zone that it is linked to. Make sure clients cannot get the same content another way:- Do not serve the same origin or Storage Zone through a second Pull Zone that has no protection.
- If your origin is a public server, make it accept requests only from the CDN.
For example, add a secret header in
onOriginRequest, and reject requests without it at the origin. - A Storage Zone does not serve files without its password, so a Storage-backed Pull Zone has no public origin to protect.