Skip to content

fix(client): declare Content-Length: 0 on empty POST, PUT and PATCH bodies - #14072

Merged
levivannoort merged 1 commit into
mainfrom
fix/client-empty-body-content-length
Oct 3, 2026
Merged

levivannoort merged 1 commit into
mainfrom
fix/client-empty-body-content-length

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Google OAuth sign-in on Cloud has failed with user_oauth2_provider_failure (424) since the OAuth providers moved onto Utopia\Client. Google's token endpoint answers 411 Length Required.

Google's token exchange sends its parameters in the query string, so the POST has an empty body. The old OAuth2::request() sent no Content-Length either, but plain curl negotiated HTTP/2 with Google, and HTTP/2 doesn't need one. The Curl adapter forces HTTP/1.1 and sent no length for an empty body, which Google refuses.

Both adapters now send Content-Length: 0 for a POST, PUT or PATCH with an empty body (RFC 9110 §8.6). Curl gets an empty CURLOPT_POSTFIELDS, with the default form Content-Type suppressed as it already is for non-empty bodies. Swoole gets the header directly. GET and other bodyless methods are unchanged.

Test Plan

  • New contract test testItDeclaresAZeroLengthForAnEmptyBodyOnMethodsThatCarryOne runs against both adapters. Without the fix it failed in all 6 cases (Curl and Swoole × POST/PUT/PATCH, each reporting no length); with the fix it passes, and GET still sends no length.
  • Against Google directly: curl --http1.1 -X POST 'https://oauth2.googleapis.com/token?...' returns 411, and --http2 returns 400. The patched adapter gets 400 for the same request (dummy credentials) instead of 411.
  • bin/monorepo check client passes.
  • Locally on macOS, testItChecksEveryRedirectHopAgainstTheDestination (both adapters) and testAnEnvironmentProxyCannotCarryARequestPastTheDestination (Curl) fail because macOS doesn't bind 127.0.0.2. They should pass on Linux CI.

Related PRs and Issues

  • Regression from the SSRF destination work that moved OAuth onto Utopia\Client.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Related: #14122

…odies

The adapters force HTTP/1.1 and sent no length for an empty body, so Google's OAuth token endpoint answered 411 Length Required and every Google sign-in failed with user_oauth2_provider_failure. The previous curl call negotiated HTTP/2, where no length is needed.
@ghost

ghost commented Oct 3, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The adapter changes and shared regression tests are consistent with the intended behavior; no concrete defects were found.

Both HTTP adapters now declare a zero-length body for empty POST, PUT, and PATCH requests, avoiding HTTP/1.1 responses such as Google's 411 Length Required. The shared adapter contract tests verify those methods send Content-Length: 0 while a bodyless GET remains unchanged.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
packages/client/src/Adapter/Curl/Client.php Uses empty POSTFIELDS for empty POST, PUT, and PATCH bodies and suppresses an implicit form Content-Type.
packages/client/src/Adapter/SwooleCoroutine/Client.php Adds Content-Length: 0 for empty, non-multipart POST, PUT, and PATCH requests without an explicit length.
packages/client/tests/Adapter/AdapterContract.php Adds shared coverage for zero-length POST, PUT, and PATCH requests and unchanged bodyless GET behavior.
packages/client/tests/server.php Adds an endpoint that echoes the received Content-Length for contract tests.

Reviewed a6f74da · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@levivannoort
levivannoort merged commit 419943d into main Oct 3, 2026
64 checks passed
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/client-empty-body-content-length (after).

Metric Before After Change
🚀 Requests/sec 209.27 210.52 ⚪ +0.6%
⏱️ Latency P50 82.26 ms 81.42 ms ⚪ -1%
⏱️ Latency P95 195.24 ms 194.6 ms ⚪ -0.3%
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 81.42 194.6 13,452 210.52 -0.64
Account 162.62 295.6 708 11.77 -37.14
TablesDB 77.05 142.59 7,316 117.88 -6.27
Storage 78.4 170.35 3,540 58.3 +9.22
Functions 122.1 238.1 1,888 31.76 +9.45

Top API waits (after)

API request Max wait (ms)
functions.create 387.08
account.name.update 382.07
account.prefs.update 378.42
tablesdb.rows.delete 374.99
tablesdb.rows.create 366.25

abnegate added a commit that referenced this pull request Oct 5, 2026
cloud#5410 re-pins server-ce to this branch and needs main at or past
ee75768: the health tests that stop asserting wall-clock ping budgets
(#14069), Content-Length: 0 on empty client bodies for OAuth token
requests (#14072) and the SDK task no longer calling setters removed in
sdk-generator 5.3.4 (#14073). Also brings the GitHub OAuth missing-user
fix (#14093) and appwrite/geo 0.3.2 (#14100). The merge is clean and the
lock is untouched; both sides still resolve appwrite/sdk-generator 5.0.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 5, 2026
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.

3 participants