# Body Size Limit with Field Extraction
#
# Combines body_limits.max_buffer_bytes with json_body_field to
# enforce a buffering cap while still performing
# body-based routing. Requests exceeding the limit receive
# 413 (Payload Too Large) before any extraction occurs.
#
# The buffering cap defaults to 64 MiB; this example lowers it to 1 KiB.
# Raise max_buffer_bytes, max_request_bytes, and the filter max_body_bytes
# together when intentionally accepting larger buffered requests.
#
# Usage:
#   cargo run -p praxis-proxy -- -c examples/configs/payload-processing/body-size-limit-with-extraction.yaml
#
#   # Small body: extracted and routed normally
#   curl -X POST http://localhost:8080/v1/chat \
#     -H "Content-Type: application/json" \
#     -d '{"model": "model-alpha-1", "prompt": "hello"}'
#
#   # Oversized body: rejected with 413
#   curl -X POST http://localhost:8080/v1/chat \
#     -H "Content-Type: application/json" \
#     -d @large-payload.json

listeners:
  - name: gateway
    address: "0.0.0.0:8080" # dev value; binds all interfaces
    filter_chains:
      - extract-model
      - routing

filter_chains:
  - name: extract-model
    filters:
      - filter: json_body_field
        field: model
        header: X-Model

  - name: routing
    filters:
      - filter: router
        routes:
          - path_prefix: "/"
            cluster: backend
      - filter: load_balancer
        clusters:
          - name: backend
            endpoints:
              - "127.0.0.1:3000"

# The 1 KiB buffering cap is stricter than the 2 KiB transfer limit.
# A 1025-byte request fails the buffering cap before extraction.
body_limits:
  max_buffer_bytes: 1024
  max_request_bytes: 2048

insecure_options:
  allow_private_endpoints: true # example proxies to local backends
