커스텀 헤더 정의

Media CDN을 사용하면 커스텀 요청 및 응답 헤더를 지정할 수 있습니다.

커스텀 헤더를 사용하면 다음을 수행할 수 있습니다.

  • 국가, 리전, 도시와 같이 지역화된 콘텐츠를 표시하는 데 사용할 수 있는 클라이언트에 대한 지리적 데이터를 반환합니다.
  • 캐시에서 응답이 제공되었는지 여부(전체 또는 일부) 그리고 제공된 캐시 위치를 확인합니다.
  • 요청 및 응답 헤더 모두를 삭제, 대체, 추가합니다.

커스텀 헤더 설정

헤더가 각 경로에 설정되어 매니페스트 또는 동영상 세그먼트와 같은 여러 콘텐츠에 대해 헤더를 추가 및 삭제할 수 있습니다.

캐싱 결정 전에 CDN 처리 경로 초기에 경로별 커스텀 요청 헤더를 설정합니다. 예를 들어 cache-control 헤더를 경로별 커스텀 헤더로 설정하면 CDN의 캐싱 동작에 영향을 미칩니다.

기본적으로 추가한 헤더 값은 쉼표로 구분되고 동일한 필드 이름의 응답 또는 요청 헤더에 추가됩니다.

기존 값을 덮어쓰려면 replacetrue로 설정합니다.

gcloud 및 YAML

EdgeCacheService 리소스의 YAML 구성을 나열하려면 다음 명령어를 사용합니다.

gcloud edge-cache services describe prod-media-service

.routing.pathMatchers[].routeRules[].headerAction 섹션에는 추가 및 삭제할 헤더가 표시됩니다.

routeRules:
- priority: 1
   description: "video routes"
   matchRules:
      - prefixMatch: "/video/"
   headerAction:
      responseHeadersToAdd:
      # Return the country (or region) associated with the client's IP address.
      - headerName: "client-geo"
         headerValue: "{client_region}"
         replace: true
      requestHeadersToAdd:
      # Inform the upstream origin server the request is from Media CDN
      - headerName: "x-downstream-cdn"
         headerValue: "Media CDN"
      responseHeadersToRemove:
      - headerName: "X-User-ID"
      - headerName: "X-Other-Internal-Header"

Terraform

다음 Terraform 스니펫은 커스텀 헤더가 있는 라우팅 규칙을 보여줍니다.

route_rule {
  description = "video routes"
  priority    = 1
  match_rule {
    prefix_match = "/video/"
  }
  origin = google_network_services_edge_cache_origin.default.name
  header_action {
    response_header_to_add {
      # Return the country (or region) associated with the client's IP address.
      header_name  = "client-geo"
      header_value = "{client_region}"
      replace      = true
    }
    request_header_to_add {
      # Inform the upstream origin server that the request is from Media CDN.
      header_name  = "x-downstream-cdn"
      header_value = "Media CDN"
    }
    response_header_to_remove {
      header_name = "X-User-ID"
    }
    response_header_to_remove {
      header_name = "X-Other-Internal-Header"
    }
  }
}

이 예시에서는 다음을 수행합니다.

  • 클라이언트의 IP 주소와 연결된 국가(또는 리전)를 반환하는 {client_region} 변수를 사용하여 응답에 커스텀 client-geo 헤더를 추가합니다.
  • 정적 문자열을 사용해서 요청에 커스텀 x-downstream-cdn 헤더를 추가합니다.
  • 2개의 내부 헤더를 삭제합니다.

원본별 커스텀 헤더를 구성하려면