Skip to content

feat(upstream): support http_400/http_401/http_402 in set_next_upstream - #120

Open
oowl wants to merge 1 commit into
masterfrom
ai-proxy-advanced-fallback-401
Open

feat(upstream): support http_400/http_401/http_402 in set_next_upstream#120
oowl wants to merge 1 commit into
masterfrom
ai-proxy-advanced-fallback-401

Conversation

@oowl

@oowl oowl commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Expose next_upstream masks for HTTP 400, 401 and 402 so that resty.kong.upstream.set_next_upstream() accepts these status codes. Previously only 403/404/429 were supported among 4xx, so passing e.g. http_401 returned "argument #i is not a valid argument".

Changes

  • src/ngx_http_lua_kong_module.c: export ngx_http_lua_kong_next_upstream_mask_http_400/401/402.
  • lualib/resty/kong/upstream.lua: declare the new externs in the ffi.cdef and add them to next_upstream_table.

Dependency

Requires the matching nginx core flags NGX_HTTP_UPSTREAM_FT_HTTP_400/401/402, added on the Kong side via an OpenResty patch (nginx-1.27.1_26-upstream-next-extra-4xx.patch in kong-ee). Without the patch the module will fail to compile (undefined NGX_HTTP_UPSTREAM_FT_HTTP_40x).

Motivation

Lets ai-proxy-advanced failover to the next target/provider when an upstream returns 400/401/402 (e.g. expired/invalid API key → 401).

🤖 Generated with Claude Code

Consumer

Used by Kong/kong-ee#19297 (ai-proxy-advanced failover_criteria http_400/401/402).

Expose next_upstream masks for HTTP 400, 401 and 402 so that
set_next_upstream() accepts these status codes, enabling failover on
them (e.g. ai-proxy-advanced failover_criteria). Requires the matching
nginx core flags NGX_HTTP_UPSTREAM_FT_HTTP_400/401/402.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant