Skip to content

Improves the proxy: status HTTP, timeouts, cache, fallback stale and URL resolver - #32

Merged
edersoares merged 14 commits into
mainfrom
proxy-improvements
Sep 24, 2026
Merged

edersoares merged 14 commits into
mainfrom
proxy-improvements

Conversation

@edersoares

@edersoares edersoares commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Contexto

Análise do uso do Frontier no i-Educar (UI Nuxt sob /new, proxy) apontou quatro pontos fracos no
FrontendProxyController: sem timeout, status HTTP não repassado, cache em arquivo inutilizável em produção,
e nenhuma forma de fixar a versão da UI por tenant. Durante a implementação apareceram mais dois bugs:
parsing de segmentos das regras e caminho duplicado (host/web/web) para regras com prefixo.

Cada mudança é um commit isolado, com teste próprio. Cobertura de testes em 100% do início ao fim.

Mudanças

Correções

  • Segmentos cache e methods(...) de uma regra passam a valer em qualquer posição, não só como último segmento.
  • O caminho pedido ao host agora espelha o do navegador, inclusive barra final. Antes uma regra com prefixo
    (/new) pedia host/new/new em vez de host/new.
  • A query string, antes descartada em GET/HEAD, é repassada ao host e entra na chave de cache.

Funcionalidades

  • O status HTTP do host é repassado ao cliente. Um 404/500 do CDN deixa de virar 200, e respostas com
    falha não são cacheadas.
  • Timeouts explícitos (FRONTIER_PROXY_TIMEOUT, FRONTIER_PROXY_CONNECT_TIMEOUT). Falha de conexão responde
    504 em vez de travar o worker do PHP-FPM.
  • Cache do proxy migrado de arquivo por servidor para a Cache facade, chaveado pela URL final (host + uri +
    query), com TTL configurável e header X-Frontier-Cache: hit|miss.
  • Fallback "stale": a última cópia boa é servida com 200 quando o host responde 5xx ou não responde,
    enquanto 4xx continua sendo repassado como está.
  • Frontier::resolveUrlUsing() permite resolver a URL do proxy em tempo de requisição, por exemplo para
    fixar a versão da UI por tenant.

Docs

  • README: tabela de segmentos das regras, envs novas, comportamento do cache e do fallback, exemplo do
    resolver, e nota de que essas melhorias valem só para o tipo proxy (o tipo http mantém o cache antigo).
  • Duas envs pré-existentes que nunca tinham sido documentadas (FRONTIER_DEFAULT_ENABLED,
    FRONTIER_PROXY_ENABLED) e um typo antigo na descrição de FRONTIER_CACHE.

Breaking change

O cache do proxy não é mais limpo por php artisan view:clear. Agora é php artisan cache:clear, ou apontar
FRONTIER_PROXY_CACHE_STORE para um store dedicado que possa ser limpo isoladamente.

Validação

  • composer test (Pest): 42 passed.
  • XDEBUG_MODE=coverage vendor/bin/pest --coverage: 100.0% em todas as classes.
  • composer lint (Pint): sem alterações pendentes.

🤖 Generated with Claude Code

edersoares and others added 14 commits September 24, 2026 10:19
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…the rule

The cache flag and the methods list were reset on every segment of a proxy
rule, so `cache` and `methods(...)` only took effect as the last segment.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Responses from the proxied host were always returned as 200. The status is now
forwarded as is and failed responses are no longer written to the cache.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… failure

Requests to the proxied host now use FRONTIER_PROXY_TIMEOUT (5s) and
FRONTIER_PROXY_CONNECT_TIMEOUT (2s). A connection failure returns 504 instead
of raising an exception.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The file based cache was per server, keyed only by the host and never
expired. Cached GET responses now live in the configured cache store, keyed by
the final URL, with a TTL (FRONTIER_PROXY_CACHE_TTL, 60s) and an
X-Frontier-Cache header reporting hit or miss.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Successful cached responses are also kept as a stale copy for
FRONTIER_PROXY_CACHE_STALE_TTL (24h). When the host answers a 5xx or cannot be
reached, the stale copy is served with X-Frontier-Cache: stale. Client errors
are still forwarded untouched.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Frontier::resolveUrlUsing() registers a callback that receives the URL, the
current request and the rule config, so apps can pin a frontend version per
tenant. The cache key uses the resolved URL.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A rule with a prefix such as /new answered /new by fetching host/new/new,
because the default of the optional {uri?} parameter repeated the prefix. The
proxied path now mirrors the requested one, trailing slash included. The
request is injected per invocation instead of the constructor, since the route
reuses the controller instance in long running processes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
GET and HEAD requests dropped the query string, so an asset requested as
/x.js?v=1 reached the host as /x.js. The query is now part of the proxied URL,
which also makes the cache key and the URL resolver see it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…he proxy type

FRONTIER_DEFAULT_ENABLED and FRONTIER_PROXY_ENABLED were missing from the env
var table, and FRONTIER_CACHE had a typo. Also note that status forwarding,
timeouts, cache and the URL resolver only apply to the proxy type, not http.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The task plan was a working document for this branch, not reference
documentation for the library.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@edersoares edersoares changed the title Robustece o proxy: status HTTP, timeouts, cache via Redis, fallback stale e resolver de URL Improves the proxy: status HTTP, timeouts, cache, fallback stale and URL resolver Sep 24, 2026
@edersoares
edersoares merged commit e113618 into main Sep 24, 2026
1 check passed
@edersoares
edersoares deleted the proxy-improvements branch September 24, 2026 16:56
edineivaldameri pushed a commit to edineivaldameri/frontier that referenced this pull request Oct 7, 2026
The proxy improvements merged in edersoares#32 change the behavior of the proxy
type and are not released yet. The changelog records them under
Unreleased so the next release has its notes ready.

FRONTIER_PROXY was documented in the README and covered by a test, but
nothing in the package reads it.

Co-Authored-By: Claude Fable 5.1 <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