Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Resources
      • Creating a resource
      • Editing basic settings of a resource
      • Configuring resource caching
      • Configuring log export
      • Pre-loading files to CDN servers
      • Purging resource cache
      • Configuring request and response headers
      • Configuring CORS for responses to clients
      • Configuring HTTP methods
      • Enabling file compression
      • Enabling file segmentation
      • Enabling origin shielding
      • Disabling a resource
      • Deleting a resource
    • Origin groups
      • Creating an origin group
      • Editing an origin group
      • Connecting an origin group to a resource
      • Deleting an origin group
  • Practical guidelines
    • All practical guidelines
    • Publishing game updates
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment of service versions
  • Concepts
    • Service overview
    • Resource
    • Origins and origin groups
    • Exchanging data between clients and the CDN
      • Overview
      • TLS certificates
      • CORS
      • Compressing content
    • Exchanging data between the CDN and origins
      • Overview
      • Host header
      • Content segmentation
      • Origin shielding
    • Caching content
    • Exporting logs
    • Quotas and limits
  • Access management
  • Troubleshooting
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • CacheService
      • OriginGroupService
      • OriginService
      • ProviderService
      • RawLogsService
      • ResourceService
      • OperationService
    • REST
      • Overview
      • Cache
        • Overview
        • prefetch
        • purge
      • OriginGroup
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Origin
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Provider
        • Overview
        • activate
        • listActivated
      • RawLogs
        • Overview
        • activate
        • deactivate
        • get
        • update
      • Resource
        • Overview
        • create
        • delete
        • get
        • getProviderCName
        • list
        • update
  • Pricing policy
  1. Step-by-step instructions
  2. Resources
  3. Configuring request and response headers

Configuring HTTP headers of requests and responses

Written by
Yandex Cloud

    To configure, for your resource, the HTTP headers of requests and responses:

    Note

    The Access-Control-Allow-Origin header for the CORS configuration is configured under CORS when responding to client requests. For more information, see Configuring CORS when responding to clients.

    Management console
    CLI
    Terraform
    1. In the management console, select the folder where your resource is located.

    2. Select Cloud CDN.

    3. Click the name of the desired resource.

    4. Go to HTTP headers and methods.

    5. In the top right-hand corner, click Edit.

    6. Under Origin request headers:

      • In the Header field, click Add.
      • Enter names and values of the desired headers.
    7. Under Client response headers:

      • In the Header field, click Add.
      • Enter names and values of the desired headers.
    8. Click Save.

    If you don't have the Yandex Cloud command line interface yet, install and initialize it.

    The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

    1. View a description of the CLI update resource command:

      yc cdn resource update --help
      
    2. Get a list of all resources in the default folder:

      yc cdn resource list --format yaml
      

      Result:

      id: someidkfjqjfl325fw
      folder_id: somefolder7p3l5eobbd
      cname: testexample.com
      created_at: "2022-01-19T09:23:57.921365Z"
      updated_at: "2022-01-19T10:55:30.305141Z"
      active: true
      options:
        edge_cache_settings:
          enabled: true
          default value: "345600"
        cache_http_headers:
          enabled: true
          value:
          - content-type
          - content-length
          - connection
          - server
          - date
          - test
        stale:
          enabled: true
          value:
          - error
          - updating
        allowed_http_methods:
          value:
          - GET
          - POST
          - HEAD
          - OPTIONS
      origin_group_id: "89783"
      origin_group_name: My origins group
      origin_protocol: HTTP
      ssl_certificate:
        type: DONT_USE
        status: READY
      
    3. To add headers, run:

      yc cdn resource update <resource ID> \
        --static-request-headers <key=value> \
        --static-headers <key=value>
      

      Where:

      • --static-request-headers adds request headers to the source. You can remove them using the --clear-static-request-headers flag.
      • --static-headers adds client response headers. You can remove them using the --clear-static-headers flag.

      For more information about the yc cdn resource update command, see the CLI reference.

    If you don't have Terraform, install it and configure the Yandex Cloud provider.

    1. In the configuration file, describe the parameters of the CDN resource to create:

      terraform {
        required_providers {
          yandex = {
            source  = "yandex-cloud/yandex"
            version = "0.69.0"
          }
        }
      }
      
      provider "yandex" {
        token     = "<OAuth>"
        cloud_id  = "<cloud ID>"
        folder_id = "<folder ID>"
        zone      = "<availability zone>"
      }
      
      resource "yandex_cdn_resource" "my_resource" {
          cname               = "cdn1.yandex-example.ru"
          active              = false
          origin_protocol     = "https"
          secondary_hostnames = ["cdn-example-1.yandex.ru", "cdn-example-2.yandex.ru"]
          origin_group_id     = yandex_cdn_origin_group.my_group.id
          options {
            cache_http_headers = ["GET","PUT"]
            cors                 = ["*"]
            static_response_headers = { "world2" = "2hello" }
      
          }
      
      }
      

      Where:

      • cname: The primary domain name used for content distribution. Required parameter.
      • active: A flag that indicates if content is available to end users. True: Content from the CDN is available to clients. Optional parameter, defaults to true.
      • origin_protocol: Origin protocol. Optional parameter, defaults to http.
      • secondary_hostnames: Additional domain names. Optional.
      • origin_group_id: ID of the origin group. Required parameter. Use the ID from the description of the origin group in the yandex_cdn_origin_group resource.
      • The options section contains additional parameters of CDN resources:
        • static_response_headers: Custom headers that CDN servers send in response to the client. Optional.

      For more information about yandex_cdn_resource parameters in Terraform, see the provider documentation.

    2. In the command line, go to the directory with the Terraform configuration file.

    3. Check the configuration using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    4. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    5. Apply the configuration changes:

      terraform apply
      
    6. Confirm the changes: type yes into the terminal and press Enter.

      You can check the changes to the CDN resource in the management console or using the CLI:

      yc cdn resource list
      

    It may take up to 15 minutes for the new settings of the existing resource to apply to CDN servers. After that, we recommend purging the resource cache.

    See also

    • Configuring data exchange between clients and the CDN
    • Configuring data exchange between CDN servers and origins

    Was the article helpful?

    Language / Region
    Yandex project
    © 2023 Yandex.Cloud LLC