ngx_addon_name=ngx_http_cache_turbo_module

CACHE_TURBO_SRCS="                                                       \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_module.c      \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_conf.c        \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_admin.c       \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_shm.c         \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_swr.c         \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_autotune.c    \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_redis.c       \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_memcached.c   \
                  "

CACHE_TURBO_DEPS="                                                      \
                  $ngx_addon_dir/src/ngx_http_cache_turbo_module.h      \
                  "

# This module captures the upstream response body, so it depends on the
# postpone filter being activated (same requirement as srcache).
if [ ! -z "$HTTP_POSTPONE" ]; then
    if [ -z "$HTTP_POSTPONE_FILTER_MODULE" ]; then
        HTTP_POSTPONE_FILTER_MODULE=ngx_http_postpone_filter_module
        HTTP_POSTPONE_FILTER_SRCS=src/http/ngx_http_postpone_filter_module.c
    fi
    if [ "$HTTP_POSTPONE" != YES ]; then
        HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_POSTPONE_FILTER_MODULE"
        HTTP_SRCS="$HTTP_SRCS $HTTP_POSTPONE_FILTER_SRCS"
        HTTP_POSTPONE=YES
    fi
fi

if [ -n "$ngx_module_link" ]; then
    ngx_module_type=HTTP_AUX_FILTER
    ngx_module_name=$ngx_addon_name
    ngx_module_srcs="$CACHE_TURBO_SRCS"
    ngx_module_deps="$CACHE_TURBO_DEPS"
    # NO ngx_module_order: a lone --add-dynamic-module filter is appended last
    # at ./configure and registers at the TOP of the output chain, so our body
    # filter captures the IDENTITY response body BEFORE gzip/zstd/brotli compress
    # it. Capturing below them stores a coding-specific body + Content-Encoding
    # and replays e.g. a zstd body to a gzip/identity client on a HIT (browser
    # "Content Encoding Error" — 2026-06-13 incident). In the angie package build
    # (many dynamic filters) cache_turbo is made the LAST --add-dynamic-module in
    # debian/rules for the same reason. An explicit ngx_module_order here only
    # PULLED us back down below the compression filters, so we deliberately set
    # none and rely on being registered last.
    . auto/module
else
    HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $CACHE_TURBO_SRCS"
    NGX_ADDON_DEPS="$NGX_ADDON_DEPS $CACHE_TURBO_DEPS"
fi
