{
    debug
    log {
        level debug
    }
    cache {
        allowed_http_verbs GET POST
        api {
            prometheus
            souin
        }
        cdn {
            dynamic
            strategy hard
        }
        regex {
            exclude /test2.*
        }
        ttl 1000s
        timeout {
            backend 10s
            cache 100ms
        }
        default_cache_control public
    }
}

:4443
respond "Hello World!"

@match path /test1*
@match2 path /test2*
@matchdefault path /default
@souin-api path /souin-api*

cache @match {
    ttl 5s
}

cache @match2 {
    ttl 50s
}

cache @matchdefault {
    ttl 5s
}

route /badger-configuration {
    cache {
        ttl 15s
        badger {
            configuration {
                Dir /tmp/badger-configuration
                ValueDir match2
                ValueLogFileSize 16777216
                MemTableSize 4194304
                ValueThreshold 524288
            }
        }
    }
    respond "Hello badger"
}

route /etcd {
    cache {
        ttl 5s
        etcd {
            configuration {
                Endpoints etcd1:2379 etcd2:2379 etcd3:2379
                AutoSyncInterval 1s
                DialTimeout 1s
                DialKeepAliveTime 1s
                DialKeepAliveTimeout 1s
                MaxCallSendMsgSize 10000000
                MaxCallRecvMsgSize 10000000
                Username john
                Password doe
                RejectOldCluster false
                PermitWithoutStream false
            }
        }
    }
    respond "Hello etcd"
}

route /etcd-configuration {
    cache {
        ttl 5s
        etcd {
            configuration {
                Endpoints etcd:2379 etcd:2379
                AutoSyncInterval 1s
                DialTimeout 1s
                DialKeepAliveTime 1s
                DialKeepAliveTimeout 1s
                MaxCallSendMsgSize 10000000
                MaxCallRecvMsgSize 10000000
                RejectOldCluster false
                PermitWithoutStream false
            }
        }
    }
    respond "Hello etcd"
}

route /nats {
    cache {
        ttl 5s
        nats {
            url nats://127.0.0.1:4222
        }
    }
    respond "Hello nats"
}

route /nats-configuration {
    cache {
        ttl 5s
        nats {
            configuration {
                Servers nats://127.0.0.1:4222
            }
        }
    }
    respond "Hello nats"
}

route /nuts-configuration {
    cache {
        ttl 15s
        nuts {
            configuration {
                Dir /tmp/nuts-configuration
                EntryIdxMode 1
                RWMode 0
                SegmentSize 1024
                NodeNum 42
                SyncEnable true
                StartFileLoadingMode 1
            }
        }
    }
    respond "Hello nuts"
}

route /redis {
    cache {
        ttl 5s
        redis {
            configuration {
                ClientName souin-redis
                InitAddress 127.0.0.1:6379
                SelectDB 0
            }
        }
    }
    respond "Hello redis"
}

route /redis-configuration {
    cache {
        ttl 5s
        redis {
            configuration {
                ClientName souin-redis
                InitAddress 127.0.0.1:6379
                SelectDB 0
            }
        }
    }
    respond "Hello redis"
}

route /redis-url {
    cache {
        ttl 5s
        redis {
            url 127.0.0.1:6379
        }
    }
    respond "Hello redis url"
}

route /vary {
    cache {
        ttl 15s
    }
    header Vary X-Something
    respond "Hello {http.request.header.X-Something}"
}

route /cache-s-maxage {
    cache
    header Cache-Control "s-maxage=10"
    respond "Hello, s-maxage!"
}

route /cache-maxage {
    cache
    header Cache-Control "max-age=5"
    respond "Hello, max-age!"
}

route /cache-maxstale {
    cache {
        ttl 3s
        stale 5s
    }
    header Cache-Control "max-age=5"
    respond "Hello, max-age!"
}

route /not-modified {
    cache {
        ttl 5s
    }
    reverse_proxy 127.0.0.1:9000
}

route /no-reverse-proxy {
    cache
    reverse_proxy 127.0.0.1:9000
}

route /surrogate-keys {
    cache
    header Surrogate-Key "KEY-{http.request.header.X-Surrogate-Key-Suffix}"
    header Vary X-Surrogate-Key-Suffix,Accept-Encoding
    respond "Hello {http.request.header.X-Surrogate-Key-Suffix}"
}

route /another-cache-status-name {
    cache {
        cache_name Another
    }
}

route /backend-timeout {
    cache {
        timeout {
            backend 1s
            cache 1ms
        }
    }
    reverse_proxy 127.0.0.1:8081
}

route /stream {
    cache
    reverse_proxy 127.0.0.1:81
}

route /gzip {
    cache
    encode {
        gzip
        minimum_length 5
    }
    header Content-Type text/plain
    respond "Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip. Hello, gzip."
}

route /custom-key/without-* {
    cache {
        cache_keys {
            body {
                disable_body
            }
            host {
                disable_host
            }
            method {
                disable_method
            }
            everything-with-content-type {
                disable_method
                headers Content-Type
            }
        }
    }
    respond "Hello to the authenticated user."
}

route /must-revalidate {
    cache {
        ttl 5s
        stale 5s
    }
    header Cache-Control "must-revalidate"
    reverse_proxy 127.0.0.1:81
}

route /cache-authorization {
    cache {
        cache_keys {
            /.+ {
                headers Authorization
            }
        }
    }
    header Souin-Cache-Control public
    respond "Hello to the authenticated user."
}

route /bypass {
    cache {
        mode bypass
    }

    header Cache-Control "no-store"
    respond "Hello bypass"
}

route /bypass_request {
    cache {
        mode bypass_request
    }

    respond "Hello bypass_request"
}

route /bypass_response {
    cache {
        mode bypass_response
    }

    header Cache-Control "no-cache, no-store"
    respond "Hello bypass_response"
}

route /strict_request {
    cache {
        mode strict
    }

    respond "Hello strict"
}

route /strict_response {
    cache {
        mode strict
    }

    header Cache-Control "no-cache, no-store"
    respond "Hello strict"
}

cache @souin-api {
}

# ESI part
route /esi-include {
    cache
    header Content-Type text/html
    respond "<h1>ESI INCLUDE</h1>"
}

route /alt-esi-include {
    cache
    header Content-Type text/html
    respond "<h1>ALTERNATE ESI INCLUDE</h1>"
}

route /esi {
    cache
    header Content-Type text/html
    respond `<esi:include src="http://localhost:4443/esi-include" alt=http://localhost:4443/alt-esi-include />`
}