Skip to content

refactor: replace utopia-php/fetch with client - #13893

Merged
ChiragAgg5k merged 6 commits into
mainfrom
refactor/replace-fetch-with-client
Sep 26, 2026
Merged

ChiragAgg5k merged 6 commits into
mainfrom
refactor/replace-fetch-with-client

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

utopia-php/fetch is archived, so instead of absorbing it (#13828) every call site moves to packages/client.

- use Utopia\Fetch\Client;
- $response = (new Client())->setTimeout(15000)->fetch($url);
- $body = $response->getBody();
+ use Utopia\Client\Adapter\Curl\Client as CurlAdapter;
+ use Utopia\Client\Client;
+ $response = (new Client(new CurlAdapter()))->withTimeout(15)->withFollowRedirects(maxHops: 5)->sendRequest($request);
+ $body = (string) $response->getBody();

Call sites

Area Files
OAuth2 credential checks Cloudflare, GitHub, HuggingFace, Kakao, Resend
Auth PasswordPwned/{Appwrite,HIBP}, OIDC/Jwks
Avatars AvatarPhotos/Photo, Image/Get, Favicon/Get, Screenshots/Get
Other Health Geo/Get, Messaging Webhook, Tasks/Install

Mapping

fetch client
setTimeout(ms) / setConnectTimeout(ms) withTimeout(s) / withConnectTimeout(s)
default 15 s timeout explicit withTimeout(15) (client defaults to 30 s)
follow redirects (max 5) withFollowRedirects(maxHops: 5)
setAllowRedirects(false) client default
setUserAgent() / addHeader() withHeaders([...]) or a request header
JSON / form / query body RequestFactory::body(..., ContentType::JSON) / form() / query()
getBody() / json() (string) getBody() / json_decode(..., JSON_THROW_ON_ERROR)
catch (Utopia\Fetch\Exception) catch (ClientExceptionInterface)

PasswordPwned validators and Favicon::safeFetch() now take a PSR-18 ClientInterface; tests use named fakes.

Depends on #13910

Stacked on #13910, which adds withFollowRedirects(maxHops:) and resends in-memory bodies on 307/308 in packages/client. This PR changes no library code.

Behaviour changes

Where Before After
Kakao credential check multipart body under a urlencoded Content-Type the urlencoded body its header declares
All sites no Accept-Encoding compressed responses, decoded transparently
Form / query encoding spaces as + spaces as %20 (no current value has spaces)

Everything else (timeouts, redirect policy, headers, status checks, error handling) is unchanged. The installer's readiness probe sets Host: $domain on each request, as makeApiCall() does.

utopia-php/fetch leaves root require but stays in the lock until audit and vcs are absorbed.

Test Plan

Check Result
composer lint pass
PHPStan on touched files no errors
phpunit tests/unit/{Auth,Network,Utopia/Messaging,AvatarPhotos} 308 pass
composer refactor:check clean

E2E to watch: Avatars, Health geo, OAuth2 providers, Messaging webhook, installer.

Related PRs and Issues

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Replaces HTTP client library across the codebase.

The PR appears safe to merge; no new actionable issue was established in its current changeset.

Summary

This PR replaces utopia-php/fetch at the listed application call sites with PSR-18 requests through packages/client. It updates request and response handling, adapts test fakes, and removes the root fetch requirement.

Reviews (16) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

Comment thread src/Appwrite/Platform/Tasks/Install.php Resolved
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → refactor/replace-fetch-with-client (after).

Metric Before After Change
🚀 Requests/sec 191.49 196.48 ⚪ +2.6%
⏱️ Latency P50 89.18 ms 88.96 ms ⚪ -0.2%
⏱️ Latency P95 211.61 ms 200.9 ms 🟢 -5.1%
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 88.96 200.9 12,483 196.48 -10.71
Account 168.3 310.62 657 10.93 -3.21
TablesDB 86.58 160.79 6,789 108.78 -0.74
Storage 81.75 176.57 3,285 54.46 -14.96
Functions 122 246.62 1,752 29.66 -21.57

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.delete 561.27
account.name.update 420.26
account.prefs.update 417.1
account.get 408.74
storage.files.create 393.17

Comment thread src/Appwrite/Platform/Tasks/Install.php Resolved
Comment thread packages/client/tests/ClientTest.php Resolved
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

utopia-php/fetch is archived, so every Appwrite call site moves to packages/client (PSR-18) instead of absorbing it. Timeouts, the 5-hop redirect cap, headers, status checks and error handling are kept; the installer's readiness probe sends Host: $domain on each request. utopia-php/fetch leaves the root require and stays in the lock until audit and vcs are absorbed.
@ChiragAgg5k
ChiragAgg5k force-pushed the refactor/replace-fetch-with-client branch from 6aeb299 to b8331e3 Compare September 25, 2026 19:19
@ChiragAgg5k
ChiragAgg5k changed the base branch from main to feat/client-redirect-hops September 25, 2026 19:19
Base automatically changed from feat/client-redirect-hops to main September 26, 2026 10:06
pull Bot pushed a commit to AmirulAndalib/appwrite that referenced this pull request Sep 26, 2026
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 appwrite#13893 can keep fetch's 5-hop cap and body-preserving redirects.
@ChiragAgg5k
ChiragAgg5k merged commit 692be06 into main Sep 26, 2026
50 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the refactor/replace-fetch-with-client branch September 26, 2026 15:28
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