Skip to main content

Add or hide response headers

Orange's CDN provides two options for controlling response headers: Response headers (add) adds custom HTTP headers to CDN server responses, and Response headers (hide) removes specific origin headers before delivery.

Add response headers

The Response headers (add) option sets custom HTTP headers that CDN servers include in responses to end users. If the same header is already configured on the origin server, the CDN server overrides its value.

To configure the option:

1. In the CDB Technical Web Portal, navigate to CDN → CDN resources.

2. Click the resource to open its settings.

3. In the left panel, click HTTP headers to expand the section, then click Response headers (add) to jump to the option.

4. Enable the Add response headers toggle.

Up to 50 response headers can be added per resource.
CDN resource settings with the Response headers add option expanded, showing Header name and Value fields

5. In the Header name field, enter a header name.

6. In the Value field, enter the header value.

7. The Always add the header to response from CDN regardless of response code checkbox is enabled by default, which adds the header to all responses. To add the header only to responses with codes 200, 201, 204, 206, 301, 302, 303, 304, 307, and 308, uncheck the box.

8. Click Add header to add more headers. Fill in the fields for each additional header.

9. Click Save changes.

Add multiple header values

To add more than one value to the same header, enter them in the Value field in one of two ways:

  • Separate header values: enter a value and press Enter before adding the next one.
Response headers add form with multiple values entered on separate lines in the Value field

The response header appears as:

Example: one   
Example: two   
Example: three 
  • Comma-separated value: enter multiple values separated by commas without pressing Enter.
Response headers add form with comma-separated values in the Value field

The response header appears as:

Example: one, two, three

Both methods can be combined: enter comma-separated values, press Enter, and then add another value.

Response headers add form with combined comma-separated and multi-line values in the Value field

The response header appears as:

Example: one, two   
Example: three 

Valid characters for fields:

  • Header name: Latin letters (A–Z, a–z), numbers (0–9), underscore (_) and hyphen (-)
  • Value: Latin letters (A–Z, a–z), numbers (0–9), a space, and these characters: ~!@#%^&*()-_=+ /|";:?.><{}[]

Value field restrictions:

  • Invalid characters: $'
  • The value must start with a letter, number, asterisk (*), or opening brace ({)
  • Cannot contain only special characters

Check headers

After saving the configuration, verify the header appears in CDN responses.

1. Clear the cache of the CDN resource or files for which the header was added.

2. Run this cURL command, substituting the file URL:

curl -I https://cdn.site.com/images/1.jpg
HTTP/2 200
X-Custom-Header: header-value

3. If the response contains the configured header, the setup is complete.

Hide response headers

By default, a CDN server passes all HTTP headers it receives from the origin server to end users. To control which headers are included in responses:

1. In the Customer Portal, navigate to CDN → CDN resources.

2. Click the resource to open its settings.

3. In the left panel, click HTTP headers to expand the section, then click Response headers (hide) to jump to the option.

4. Enable the Hide response headers toggle.

CDN resource settings with the Response headers hide option enabled, showing Hide all except and Hide only radio buttons

5. Select a mode:

  • Hide all except — set the headers to keep in the response; all other headers are hidden. After enabling, the most common headers appear pre-filled. Remove headers by clicking the × icon, or add headers by clicking the HTTP headers row and selecting from the list or entering a name. Header names accept letters (a–z), numbers (0–9), dashes (-), and underscores (_).
Hide all except mode with pre-populated common response headers shown as removable tags
  • Hide only — set the headers to hide from the response; all other headers are kept. Click the HTTP headers row and select from the list or enter custom header names.
Hide only mode with an empty field for entering headers to hide from responses
The following headers are mandatory and cannot be hidden: connection, content-length, content-type, server, and date.

6. Click Save changes.

Add custom headers to CDN responses, or hide selected origin headers before the response is delivered.

An API token is required. The CDN resource ID is visible under CDN → CDN Resources, or from the resources list call.

Use static_response_headers to add headers. The older staticHeaders field is not used for new configurations. Use response_headers_hiding_policy to hide origin headers. Set enabled to false to turn either option off.

Open a terminal and export the required variables:

export GCORE_API_KEY="{YOUR_API_KEY}"
export CDN_RESOURCE_ID="{YOUR_CDN_RESOURCE_ID}"

Add response headers

Set options.static_response_headers. Each item in value is one header. Strings in that item's value array are separate header values. A comma inside one string stays part of that single value. always set to false adds the header only to responses with codes 200, 201, 204, 206, 301, 302, 303, 304, 307, and 308. always set to true adds it to every response. A resource accepts up to 50 headers. The name uses letters, numbers, hyphens, and underscores. The value must start with a letter, number, asterisk (*), or opening brace ({).

After the option is saved, clear the cache and request the file. The header is present when the CDN response includes it.

import os

from gcore import CDB

client = CDB()
resource_id = int(os.environ["CDN_RESOURCE_ID"])

updated = client.cdn.cdn_resources.update(
    resource_id,
    options={
        "static_response_headers": {
            "enabled": True,
            "value": [
                &#123;
                    "name": "X-Custom-Header",
                    "value": ["one", "two"],
                    "always": False,
                &#125;
            ],
        }
    },
)
header = updated.options.static_response_headers.value[0]
print(header.name, header.value, header.always)
package main

import (
    "context"
    "fmt"
    "os"
    "strconv"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()
    resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
    if err != nil {
        panic(err)
    }

    updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
        Options: cdn.CDNResourceUpdateParamsOptions{
            StaticResponseHeaders: cdn.CDNResourceUpdateParamsOptionsStaticResponseHeaders{
                Enabled: true,
                Value: []cdn.CDNResourceUpdateParamsOptionsStaticResponseHeadersValue{{
                    Name:   "X-Custom-Header",
                    Value:  []string{"one", "two"},
                    Always: gcore.Bool(false),
                }},
            },
        },
    })
    if err != nil {
        panic(err)
    }
    header := updated.Options.StaticResponseHeaders.Value[0]
    fmt.Println(header.Name, header.Value, header.Always)
}
curl -X PATCH "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "options": {
      "static_response_headers": {
        "enabled": true,
        "value": [
          &#123;
            "name": "X-Custom-Header",
            "value": ["one", "two"],
            "always": false
          &#125;
        ]
      }
    }
  }'

The API returns HTTP 200. The saved option is:

{
  "enabled": true,
  "value": [
    &#123;
      "name": "X-Custom-Header",
      "value": ["one", "two"],
      "always": false
    &#125;
  ]
}

Hide response headers

Select one policy. The API mode name does not match the Portal label.

Portal modeAPI modeexcepted contains
Hide all excepthideHeaders to keep
Hide onlyshowHeaders to remove

Hide all except selected headers

Set mode to hide. excepted lists the headers that stay. The API also keeps connection, content-length, content-type, date, and server.

import os

from gcore import CDB

client = CDB()
resource_id = int(os.environ["CDN_RESOURCE_ID"])

updated = client.cdn.cdn_resources.update(
    resource_id,
    options={
        "response_headers_hiding_policy": &#123;
            "enabled": True,
            "mode": "hide",
            "excepted": ["etag"],
        &#125;
    },
)
policy = updated.options.response_headers_hiding_policy
print(policy.mode, policy.excepted)
package main

import (
    "context"
    "fmt"
    "os"
    "strconv"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()
    resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
    if err != nil {
        panic(err)
    }

    updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
        Options: cdn.CDNResourceUpdateParamsOptions{
            ResponseHeadersHidingPolicy: cdn.CDNResourceUpdateParamsOptionsResponseHeadersHidingPolicy{
                Enabled:  true,
                Mode:     "hide",
                Excepted: []string{"etag"},
            },
        },
    })
    if err != nil {
        panic(err)
    }
    policy := updated.Options.ResponseHeadersHidingPolicy
    fmt.Println(policy.Mode, policy.Excepted)
}
curl -X PATCH "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "options": {
      "response_headers_hiding_policy": &#123;
        "enabled": true,
        "mode": "hide",
        "excepted": ["etag"]
      &#125;
    }
  }'

The API returns HTTP 200. The saved option keeps the requested header and the headers that cannot be hidden:

&#123;
  "enabled": true,
  "mode": "hide",
  "excepted": ["etag", "content-type", "content-length", "connection", "date", "server"]
&#125;

Hide only selected headers

Set mode to show. excepted lists the headers to remove. connection, content-length, content-type, date, and server cannot be removed.

import os

from gcore import CDB

client = CDB()
resource_id = int(os.environ["CDN_RESOURCE_ID"])

updated = client.cdn.cdn_resources.update(
    resource_id,
    options={
        "response_headers_hiding_policy": &#123;
            "enabled": True,
            "mode": "show",
            "excepted": ["x-robots-tag"],
        &#125;
    },
)
policy = updated.options.response_headers_hiding_policy
print(policy.mode, policy.excepted)
package main

import (
    "context"
    "fmt"
    "os"
    "strconv"

    gcore "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cdn"
)

func main() {
    client := gcore.NewClient()
    ctx := context.Background()
    resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
    if err != nil {
        panic(err)
    }

    updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
        Options: cdn.CDNResourceUpdateParamsOptions{
            ResponseHeadersHidingPolicy: cdn.CDNResourceUpdateParamsOptionsResponseHeadersHidingPolicy{
                Enabled:  true,
                Mode:     "show",
                Excepted: []string{"x-robots-tag"},
            },
        },
    })
    if err != nil {
        panic(err)
    }
    policy := updated.Options.ResponseHeadersHidingPolicy
    fmt.Println(policy.Mode, policy.Excepted)
}
curl -X PATCH "https://api.cdb-staging.cdn.orange.com/cdn/resources/$CDN_RESOURCE_ID" \
  -H "Authorization: APIKey $GCORE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "options": {
      "response_headers_hiding_policy": &#123;
        "enabled": true,
        "mode": "show",
        "excepted": ["x-robots-tag"]
      &#125;
    }
  }'

The API returns HTTP 200:

&#123;
  "enabled": true,
  "mode": "show",
  "excepted": ["x-robots-tag"]
&#125;

Add a custom response header and hide origin headers with the Terraform provider v2. CDN responses include each value of X-Custom-Header as a separate header. always set to false adds the header only to responses with codes 200, 201, 204, 206, 301, 302, 303, 304, 307, and 308. Clear the cache after terraform apply, then request the file.

Response headers

Set static_response_headers enabled to true. Each object in value is one header, and each string in that object's value is a separate header value. A resource accepts up to 50 headers. The value must start with a letter, number, asterisk (*), or opening brace ({). mode hide is Hide all except: the headers in excepted stay, and the stored list also includes connection, content-length, content-type, date, and server. mode show is Hide only: it removes the headers in excepted. Set excepted to x-robots-tag to remove that header, then run terraform apply.

resource "gcore_cdn_origin_group" "example" {
  name = "my-origin-group"

  sources = [
    {
      source  = "example.com"
      enabled = true
    }
  ]
}

resource "gcore_cdn_resource" "example" {
  cname           = "cdn.example.com"
  origin_group    = gcore_cdn_origin_group.example.id
  origin_protocol = "HTTPS"

  options = {
    static_response_headers = {
      enabled = true
      value = [
        {
          name   = "X-Custom-Header"
          value  = ["one", "two"]
          always = false
        }
      ]
    }

    response_headers_hiding_policy = {
      enabled  = true
      mode     = "hide"
      excepted = ["etag"]
    }
  }
}