#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

#
# Verify negative_revalidating disabled behavior. This replay file assumes:
#   * ATS is configured with negative_revalidating disabled.
#   * max_stale_age is set to 6 seconds.
#

meta:
  version: "1.0"

  blocks:
  - request_for_positive_max_age: &request_for_en_US
      client-request:
        method: "GET"
        version: "1.1"
        scheme: "http"
        url: /path/request
        headers:
          fields:
          - [ Host, example.com ]
          - [ Accept, "*/*" ]
          - [ Accept-Language, en_US ]
        delay: 100ms

  - request_for_positive_max_age: &request_for_es_US
      client-request:
        method: "GET"
        version: "1.1"
        scheme: "http"
        url: /path/request
        headers:
          fields:
          - [ Host, example.com ]
          - [ Accept, "*/*" ]
          - [ Accept-Language, es_US ]
        delay: 100ms

sessions:
- transactions:
  # These first two requests just store the two alternats for this url
  - all: { headers: { fields: [[ uuid, 1 ]]}}
    <<: *request_for_en_US

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Content-Length, 16 ]
        - [ Cache-Control, max-age=1 ]
        - [ Content-Language, en_US ]
        - [ Vary, Accept-Language ]


    proxy-response:
      status: 200
  - all: { headers: { fields: [[ uuid, 2 ]]}}
    <<: *request_for_es_US

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Content-Length, 20 ]
        - [ Cache-Control, max-age=1 ]
        - [ Content-Language, es_US ]
        - [ Vary, Accept-Language ]

    proxy-response:
      status: 200

  # This request serves as a way to introduce a 5 second delay so we can replace the cache objects
  - all: { headers: { fields: [[ uuid, 3 ]]}}
    client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/request
      headers:
        fields:
        - [ Host, example.com ]
        - [ Accept, "*/*" ]
        - [ Accept-Language, es_US ]
      delay: 2s
    server-response:
      status: 500
      reason: NOT USED
      headers:
        fields:
        - [ Content-Length, 20 ]
    proxy-response:
      status: 200

  # Replace the es_US alternate (this works fine)
  - all: { headers: { fields: [[ uuid, 4 ]]}}
    <<: *request_for_es_US

    server-response:
      status: 404
      reason: OK
      headers:
        fields:
        - [ Content-Length, 0 ]
        - [ Cache-Control, max-age=10 ]
        - [ Content-Language, es_US ]
        - [ Vary, Accept-Language ]

    proxy-response:
      status: 404

  # Replace the en_US alternate (this request breaks the cache)
  - all: { headers: { fields: [[ uuid, 5 ]]}}
    <<: *request_for_en_US

    server-response:
      status: 404
      reason: OK
      headers:
        fields:
        - [ Content-Length, 0 ]
        - [ Cache-Control, max-age=1 ]
        - [ Content-Language, en_US ]
        - [ Vary, Accept-Language ]

    proxy-response:
      status: 404

  # Expect a CL 0 response, but the server returns a chunked encoded, 16 byte response
  - all: { headers: { fields: [[ uuid, 6 ]]}}
    <<: *request_for_en_US

    server-response:
      status: 500
      reason: NOT USED
      headers:
        fields:
        - [ Content-Length, 0 ]
        - [ Cache-Control, max-age=1 ]

    proxy-response:
      status: 404
      headers:
        fields:
          - [ Content-Length, { value: "0", as: equal} ]


