#  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 that
# ATS is configured with negative_revalidating disabled.
#

meta:
  version: "1.0"

sessions:
- transactions:

  - client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/reques_item
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, 1 ]

    # Populate the cache with a 200 response.
    server-response:
      status: 200
      reason: "OK"
      headers:
        fields:
        - [ Content-Length, 32 ]
        - [ Cache-Control, max-age=2 ]

    proxy-response:
      status: 200

  # Verify we serve the 200 OK out of the cache if it is not stale.
  - client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/reques_item
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, 2 ]

      # Give cache IO enough time to finish.
      delay: 100ms

    # This should not reach the origin server.
    server-response:
      status: 503
      reason: "Service Unavailable"
      headers:
        fields:
        - [ Content-Length, 32 ]
        - [ Cache-Control, max-age=2 ]

    # Again, we should serve this out of the cache.
    proxy-response:
      status: 200

  # Verify we serve a 5xx response if the cached 200 OK is stale.
  - client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/reques_item
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, 3 ]

      # Make sure the item is stale per it's 2 second max-age.
      delay: 4s

    server-response:
      status: 503
      reason: "Service Unavailable"
      headers:
        fields:
        - [ Content-Length, 32 ]
        - [ Cache-Control, max-age=2 ]

    # Now the origin's 503 response should be served because
    # negative_revalidating is disabled.
    proxy-response:
      status: 503
