Skip to content

feat(client): cap redirect hops and resend in-memory bodies on 307/308 - #13910

Merged
ChiragAgg5k merged 2 commits into
mainfrom
feat/client-redirect-hops
Sep 26, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
feat/client-redirect-hops

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

Two packages/client changes that #13893 needs to keep utopia-php/fetch's redirect behaviour.

1. Redirect hop cap

public function withFollowRedirects(bool $enabled = true, int $maxHops = Redirect::MAX_HOPS): static
Adapter Enforced by
cURL CURLOPT_MAXREDIRS
Swoole redirect loop bound

fetch capped redirects at 5; client always allowed 50. Negative values throw ValueError. Custom Adapter implementations must add the parameter (CHANGELOG).

2. Resend in-memory bodies on 307/308

Body Before After
In memory, ≤ 2 MiB streamed via CURLOPT_READFUNCTION; 307/308 fails with necessary data rewind was not possible CURLOPT_POSTFIELDS; cURL replays it
Larger or file-backed streamed streamed (unchanged)

Test Plan

Check Result
bin/monorepo check client pass
bin/monorepo test client 199 tests pass

New tests: 5 hops allowed and a 6th rejected, zero and negative limits (both adapters); POST body across 307 and 308 (both adapters); an 8 MiB temporary body stays memory-bounded.

Related PRs and Issues

🤖 Generated with Claude Code

withFollowRedirects() takes an optional maxHops (default Redirect::MAX_HOPS). The cURL adapter sends in-memory bodies up to php://temp's 2 MiB buffer as CURLOPT_POSTFIELDS, which cURL can replay after a 307/308; larger and file-backed bodies keep streaming. Needed so #13893 can keep fetch's 5-hop cap and body-preserving redirects.
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] HTTP client adds redirect hop limits and request body handling.

The PR appears safe to merge, though the previously identified implementation-coupled memory assertion remains.

Fix All in Claude CodeFindings

  1. P2 Test mirrors implementation threshold ▶
Fix with agent prompt
### Issue 1
packages/client/tests/Adapter/Curl/ClientTest.php:undefined-56
This new assertion hardcodes the same 2 MiB value as `TEMP_MEMORY`. The repository requires tests to check observable behavior rather than mirror source configuration. Give the memory test an independent expectation; this requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR adds a configurable redirect-hop limit and uses CURLOPT_POSTFIELDS to replay small in-memory bodies across 307/308 redirects. Since the previous review, it has added Content-Type suppression for raw bodies and a regression test for that behavior.

Reviews (2) · Last reviewed commit: "fix(client): don't send a form Content-T..."

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/client-redirect-hops (after).

Metric Before After Change
🚀 Requests/sec 189.43 189.17 ⚪ -0.1%
⏱️ Latency P50 88.03 ms 90.81 ms ⚪ +3.2%
⏱️ Latency P95 220.79 ms 212.8 ms ⚪ -3.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 90.81 212.8 11,856 189.17 -7.99
Account 171.71 341.76 624 10.36 +44.62
TablesDB 87.51 170.26 6,448 105.18 -9.41
Storage 82.65 175.36 3,120 52.39 -9
Functions 132.37 262.53 1,664 28.61 -6.72

Top API waits (after)

API request Max wait (ms)
account.name.update 456.63
functions.variables.update 401.71
tablesdb.rows.get 389.86
tablesdb.rows.delete 388.39
functions.variables.delete 380.91

cURL adds Content-Type: application/x-www-form-urlencoded to string POSTFIELDS. When the request sets no Content-Type, the header is now suppressed, matching the streaming path.
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.

2 participants