# Advanced HTTP defaults: the "power features" of the HTTP client, all in one
# test. Exercises:
#   - cache: true                 per-VU browser-style HTTP cache (fresh hits +
#                                 ETag/Last-Modified revalidation)
#   - hosts:                      pin a hostname to a fixed address (curl --resolve)
#   - discard_response_bodies     drop bodies after reading them (high throughput)
#   - tracing: true               inject a W3C `traceparent` header per request
#   - tls.min_version/max_version pin the negotiated TLS version to 1.2..1.3
#
# Run it, optionally dumping every request/response to the console:
#   loadr run examples/21-http-advanced.yaml
#   loadr run examples/21-http-advanced.yaml --http-debug
name: http-advanced
description: Caching, host overrides, body discarding, tracing and TLS pinning

defaults:
  http:
    base_url: https://httpbin.org
    timeout: 10s

    # Serve cacheable GETs from a per-VU cache; revalidate stale entries with
    # conditional requests (If-None-Match / If-Modified-Since).
    cache: true

    # Drop response bodies once they have been read and measured. Byte counts
    # and assertions still work; nothing is retained in memory.
    discard_response_bodies: true

    # Inject a fresh W3C `traceparent` header on every request for
    # distributed-trace correlation.
    tracing: true

    # Pin DNS for this host to a fixed address, bypassing the resolver
    # (like curl --resolve). `host` -> `ip`, or `host:port` -> `ip:port`.
    hosts:
      httpbin.org: 3.224.123.21

    tls:
      # Constrain the handshake to TLS 1.2 .. 1.3.
      min_version: "1.2"
      max_version: "1.3"

scenarios:
  browse:
    executor: constant-vus
    vus: 5
    duration: 20s
    flow:
      # First GET is a cache miss and gets stored; subsequent iterations are
      # served from cache or revalidated.
      - request:
          name: cacheable
          method: GET
          url: /cache
          checks:
            - { type: status, equals: 200 }
      - think_time: { type: constant, duration: 500ms }
      - request:
          name: etag
          method: GET
          url: /etag/abc123
          checks:
            - { type: status, equals: 200 }

thresholds:
  http_req_duration: [ "p(95)<2000" ]
  http_req_failed: [ "rate<0.05" ]
  checks: [ "rate>0.95" ]
