Add, remove or change HTTP headers
Fastly can easily read and write HTTP headers at multiple stages of the request/response cycle.
VCL
Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):
Compute@Edge
Use this solution in your Compute@Edge service:
- Rust
// Remove a header from inbound requests. Perhaps your origin server // is gzipping responses and you want to stop it doing that req.remove_header(header::ACCEPT_ENCODING);
// Add a header to an inbound request before passing it to origin // Maybe to allow origin servers to validate that requests came from // the CDN? req.set_header("cdn-secret", "9yfncb340-6abf5oa-ejni22jkdg");
let mut beresp = req.send(BACKEND_NAME)?;
// Add headers to the response back to the browser beresp.set_header(header::CACHE_CONTROL, "max-age=60"); beresp.set_header(header::CONTENT_SECURITY_POLICY, "default-src 'self'");
// Remove headers from the response before sending it back to the browser beresp.remove_header("x-amz-request-id"); beresp.remove_header(header::SERVER);