Skip to content

Http resilience and fixes - #3

Open
msgrDiablo wants to merge 4 commits into
mainfrom
http-resilience-and-fixes
Open

Http resilience and fixes#3
msgrDiablo wants to merge 4 commits into
mainfrom
http-resilience-and-fixes

Conversation

@msgrDiablo

Copy link
Copy Markdown

řeší to 3 věci:

  1. Guzzle retry middlewre pro http požadavky, cockpit se tahal v každém requestu, timeouty 2s a pak 30s pro dávkové tahání, ladit se to dá normálně v common.neon ,
  2. fixy php chyb, trim tam byl málo specifický, get Entry = 1, JSON_THROW_ON_ERROR a pak lazy,
  3. README a MIT
    je to komplementární se všemi projekty kde to používáme, zpětně kompatibilni
    tag na posledním commitu pushnu teda až po ev. mergnutí jo?

Cockpit content is fetched over HTTP on every request, so a brief
backend unavailability (e.g. an nginx/Cockpit container being recreated
during a deploy) used to surface directly as "cURL error 7: Failed to
connect" and an error page for the visitor.

- Retry middleware: retries connection-level failures (ConnectException)
  and transient 5xx responses with exponential backoff (250/500/1000 ms);
  4xx responses are never retried.
- Default timeouts: connect_timeout 2 s, total timeout 30 s (0 disables
  the limit). The total timeout is deliberately generous: an exceeded
  timeout surfaces as cURL error 28 / ConnectException and is retried
  too, so a tight default would multiply the load caused by slow batch
  reads (console commands fetching whole collections) and still fail.
- New setHttpOptions() to tune retries and timeouts per project.
- The client is built once and cached instead of being recreated on
  every request; the unused base_uri was dropped (requests always pass
  absolute URLs).
…ror handling

- getAssetPath() used ltrim() with the uploads dir as its second
  argument, which treats it as a character set, not a prefix: paths
  like /storage/uploads/documents/x.pdf were mangled to cuments/x.pdf
  whenever the first path segment started with one of the characters
  of "/storage/uploads". Strip the prefix with str_starts_with() +
  substr() instead, and normalize the sizes branch the same way.
- getEntry() now passes limit 1 instead of fetching the whole
  collection just to return its first entry.
- get() decodes responses with JSON_THROW_ON_ERROR, so an invalid
  response fails with a clear JsonException instead of a null
  dereference on the next line.
- Extract initialization (onLoadEntry callbacks + wrapping nested
  arrays in Entry objects) into init() and trigger it from
  getIterator(), count() and offsetExists() too. Previously
  foreach/count/isset bypassed it, so iteration yielded raw arrays
  and skipped the callbacks (e.g. localization) unless some field
  had been read first.
- offsetGet() returns null for a missing key instead of emitting an
  "undefined array key" warning.
- toArray() recursively unwraps nested Entry objects, so it returns
  the raw underlying array even after initialization.
- offsetSet() throws InvalidArgumentException instead of a generic
  Exception.
- Write the README (it previously contained only the repo name):
  installation, Nette DI configuration, collections/singletons/Entry
  usage, assets, HTTP resilience defaults and tuning guidance (tight
  timeout for latency-sensitive pages, raised or disabled timeout for
  console commands and batch reads of large collections), callbacks
  and error handling.
- License the package as MIT: LICENSE file, composer.json license
  field and README section.
- Add a composer.json description.
@msgrDiablo
msgrDiablo requested a review from thorewi July 22, 2026 07:23
@msgrDiablo msgrDiablo self-assigned this Jul 22, 2026
@msgrDiablo msgrDiablo added bug Something isn't working enhancement New feature or request labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant