Course contentsShow
← Cloud and Infrastructure
Lesson 619 of 2,98911. CDN and Edge ComputingFree lesson

Request and Response Manipulation

Using edge functions to modify HTTP headers, URLs, and response bodies for A/B testing, redirects, and personalization.

Request and Response Manipulation

What You'll Learn

You'll discover how edge functions intercept and modify HTTP requests and responses in real-time to enable A/B testing, redirects, and personalization without touching your origin server.

The Core Idea

Think of edge functions as intelligent traffic cops at every CDN edge location. When a user's request arrives, these functions can examine it, change where it goes, what it asks for, or how it identifies itself. When the response comes back, they can modify what the user sees—all in milliseconds.

Request manipulation means altering incoming HTTP details before they reach your origin:

  • Rewriting URLs (e.g., /product → /product-v2)
  • Adding, modifying, or removing headers (authentication tokens, device info)
  • Redirecting users based on location or cookies

Response manipulation means changing what comes back from the origin:

  • Injecting custom headers (Cache-Control, security headers)
  • Modifying response bodies (inserting analytics scripts, swapping content)
  • A/B testing by serving variant HTML to different user segments

Real-World Applications

A/B Testing: Check a cookie value in the request; if user is in "Group B," rewrite the URL to fetch /homepage-variant-b.html instead of the default.

Personalization: Read geo-location headers and modify the response to show region-specific pricing or language.

Redirects: Detect old URL patterns in requests and redirect to new paths without a round-trip to your origin server.

Security: Strip sensitive headers from responses or add X-Frame-Options to prevent clickjacking.

This all happens at the edge—close to users—making these transformations fast and reducing load on your origin infrastructure.

Key Takeaway: Edge functions give you programmable control over HTTP requests and responses at the CDN edge, enabling dynamic behavior like A/B tests, redirects, and personalization without origin server involvement.