#  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.

meta:
  version: "1.0"

  blocks:

  - 404_response: &404_response
        status: 404
        reason: "Not Found"
        headers:
          fields:
          - [ Content-Length, 0 ]

sessions:
- transactions:

  # Case 1 proxy.config.http.normalize_ae:0
  # load an alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 01 ]

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, No-Accept-Encoding ]
      content:
        encoding: plain
        data: "no Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # load an alternate of empty Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, "" ]
        - [ uuid, 02 ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Empty-Accept-Encoding ]
      content:
        encoding: plain
        data: "Empty Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # Accept-Encoding header deflate would match the alternate of empty Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 03 ]
        - [ Accept-Encoding, deflate ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header br, compress would match the alternate of empty Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 04 ]
        - [ Accept-Encoding, "br, compress" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Empty-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # load an alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, gzip;q=0.8 ]
        - [ uuid, 05 ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Gzip-Accept-Encoding ]
      content:
        encoding: plain
        data: "Gzip Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # Accept-Encoding header br, compress, gzip would match the alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case1
      headers:
        fields:
        - [ Host, www.ae-0.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 06 ]
        - [ Accept-Encoding, "br, compress, gzip" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]


  # Case 2 proxy.config.http.normalize_ae:1
  # load an alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 11 ]

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, No-Accept-Encoding ]
      content:
        encoding: plain
        data: "no Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # empty Accept-Encoding header would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, "" ]
        - [ uuid, 12 ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header deflate would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 13 ]
        - [ Accept-Encoding, deflate ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header br, compress would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 14 ]
        - [ Accept-Encoding, "br, compress" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # load an alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, gzip;q=0.8 ]
        - [ uuid, 15 ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Gzip-Accept-Encoding ]
      content:
        encoding: plain
        data: "Gzip Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # Accept-Encoding header br, compress, gzip would match the alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case2
      headers:
        fields:
        - [ Host, www.ae-1.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 16 ]
        - [ Accept-Encoding, "br, compress, gzip" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Case 3 proxy.config.http.normalize_ae:2
  # load an alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 21 ]

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, No-Accept-Encoding ]
      content:
        encoding: plain
        data: "no Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # empty Accept-Encoding header would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, "" ]
        - [ uuid, 22 ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header deflate would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 23 ]
        - [ Accept-Encoding, deflate ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # load an alternate of br Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 24 ]
        - [ Accept-Encoding, "br, compress" ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Br-Accept-Encoding ]
      content:
        encoding: plain
        data: "br Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # load an alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, gzip;q=0.8 ]
        - [ uuid, 25 ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Gzip-Accept-Encoding ]
      content:
        encoding: plain
        data: "Gzip Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # Accept-Encoding header br, compress, gzip would match the alternate of br Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 26 ]
        - [ Accept-Encoding, "br, compress, gzip" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header compress, gzip would match the alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case3
      headers:
        fields:
        - [ Host, www.ae-2.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 27 ]
        - [ Accept-Encoding, "compress, gzip" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Case 4 proxy.config.http.normalize_ae:3
  # load an alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 31 ]

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, No-Accept-Encoding ]
      content:
        encoding: plain
        data: "no Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # empty Accept-Encoding header would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, "" ]
        - [ uuid, 32 ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header deflate would match the alternate of no Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 33 ]
        - [ Accept-Encoding, deflate ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: No-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # load an alternate of br Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 34 ]
        - [ Accept-Encoding, "br, compress" ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Br-Accept-Encoding ]
      content:
        encoding: plain
        data: "br Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # load an alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ Accept-Encoding, gzip;q=0.8 ]
        - [ uuid, 35 ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Gzip-Accept-Encoding ]
      content:
        encoding: plain
        data: "Gzip Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: miss, as: equal } ]

  # NOTICE: This case should load an alternate of br, gzip Accept-Encoding header.
  #         However, due to the implementation of calculate_quality_of_match(),
  #         ATS matches the alternate of gzip Accept-Encoding header.
  #         The result is DIFFERENT from the description of proxy.config.http.normalize_ae: 3
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 36 ]
        - [ Accept-Encoding, "br, compress, gzip" ]
      delay: 100ms

    server-response:
      status: 200
      reason: OK
      headers:
        fields:
        - [ Transfer-Encoding, chunked ]
        - [ Cache-Control, max-age=300 ]
        - [ Vary, Accept-Encoding ]
        - [ Connection, close ]
        - [ X-Response-Identifier, Br-Gzip-Accept-Encoding ]
      content:
        encoding: plain
        data: "Br, Gzip Accept-Encoding"

    proxy-response:
      status: 200
      headers:
        fields:
        # - [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
        # - [ X-Cache, { value: miss, as: equal } ]
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header compress, gzip would match the alternate of gzip Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 37 ]
        - [ Accept-Encoding, "compress, gzip" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # Accept-Encoding header br;q=1.1 would match the alternate of br Accept-Encoding header
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 38 ]
        - [ Accept-Encoding, "br;q=1.1" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        - [ X-Response-Identifier, { value: Br-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]

  # NOTICE: This case should make Accept-Encoding header br, gzip;q=0.8 match
  #         the alternate of br, gzip Accept-Encoding header.
  #         However, due to the implementation of calculate_quality_of_match(),
  #         ATS matches the alternate of gzip Accept-Encoding header.
  #         The result is DIFFERENT from the description of proxy.config.http.normalize_ae: 3
  - client-request:
      method: "GET"
      version: "1.1"
      url: /case4
      headers:
        fields:
        - [ Host, www.ae-3.com ]
        - [ X-Debug, x-cache]
        - [ uuid, 39 ]
        - [ Accept-Encoding, "br, gzip;q=0.8" ]
      delay: 100ms

    server-response:
      <<: *404_response

    proxy-response:
      status: 200
      headers:
        fields:
        # - [ X-Response-Identifier, { value: Br-Gzip-Accept-Encoding, as: equal } ]
        - [ X-Response-Identifier, { value: Gzip-Accept-Encoding, as: equal } ]
        - [ X-Cache, { value: hit-fresh, as: equal } ]
