Repository navigation
APIRequest.payloadBytes: the request body exactly as received (v1.36.0) - #212
Merged
Merged
Conversation
The server decoded a JSON body and dropped its bytes, so a route could not verify a signature computed over the raw body (e.g. a webhook HMAC): payloadAsBytes re-encodes the decoded payload, which changes whitespace, key order and number formats. The payload helpers now return a named record with the bytes, and toAPIRequest passes them to APIRequest.payloadBytes (also when the JSON fails to decode). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For a body received as text (a String payload, or a JSON or text MIME type), payloadAsBytes now returns payloadBytes instead of re-encoding the decoded payload: a JSON Map's toString isn't JSON, and a latin1 body differed once re-encoded as UTF-8. A route's Uint8List parameter filled from a text body now gets the body as received. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Unit: payloadAsBytes for JSON (Map and List), text in latin1, any String, a List<int> that is the received bytes, a non-text MIME type, requests built in code, and a JSON body that failed to decode. - A gzip-compressed body: payloadBytes is the decompressed body. - Over HTTP: a JSON body's payloadAsBytes keeps its spacing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- payloadBytes is read-only (an unmodifiable view), and payloadAsBytes returns a copy of it for a text body: a route can no longer change the bytes a signature check reads. - payloadAsBytes copies a List<int> payload, instead of returning the received bytes whenever the lengths matched. - A request built in code with a JSON MIME type: payloadAsBytes encodes the payload as JSON, not its toString. - A JSON body that fails to decode is logged with its length and its first 256 characters, not all of it. - Docs: payloadBytes is decompressed only with decompressPayload, null when no body is read, and costs memory for the request's life. - 1.36.0 (minor): payloadAsBytes changes behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…v1.36.0) postgres 3.7 picks a prepared statement's session by the current zone: run outside the runTx callback's zone, a call waits for the transaction to end (it used to fail). A transaction's operations may run from another zone, so a cached statement waited for its own transaction (CI hung in 'prepared statements: reused, in transactions...' since CI's pub upgrade took 3.7.0). PostgreSQLConnectionTransactionWrapper now runs cached statements in the runTx callback's zone. Dependencies: postgres ^3.7.0, sqlite3 ^3.9.2, archive ^4.7.1, googleapis_auth ^2.3.7, dart_spawner ^1.3.1, coverage ^1.16.2. mysql1 stays at ^0.22.0 (0.23 breaks the MySQL adapter: DECIMAL as String). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #212 +/- ##
==========================================
- Coverage 95.98% 95.95% -0.04%
==========================================
Files 75 75
Lines 25943 25964 +21
==========================================
+ Hits 24901 24913 +12
- Misses 1042 1051 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmpassos
added a commit
that referenced
this pull request
Nov 24, 2026
…ssed bodies, log preview - payloadAsBytes: a String payload with a JSON MIME type is the JSON text (not encoded again, which quoted it); others encoded with the library's Json encoder (entities, DateTime, toJson). Documents the copy per call. - APIServer: reads a chunked body with no Content-Type; passes a compressed body that isn't decompressed as bytes (octet-stream), not as garbage text; the JSON error log gives the body length before trimming and doesn't cut a surrogate pair. - Docs: _resolvePayloadBytes (shared buffer), _runStatement (who calls it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
APIRequest.payloadBytes: the body bytes as received, set byAPIServerwhen it reads a body. They are read-only (an unmodifiable view).APIRequest.payloadAsBytes(behavior change, hence 1.36.0): for a body received as text (aStringpayload, or a JSON or text MIME type), it returns a copy of those received bytes. Before, it re-encoded the decodedpayload.Why
The server decoded a JSON body and dropped its bytes. That left a route unable to verify a signature computed over the raw body, such as a webhook HMAC.
payloadAsBytesre-encoded the decodedpayload, and that never gave back the bytes that were sent:toStringof itsMap({a: 1}), which is not JSON;latin1body came back as UTF-8.Needed by AllDely's Open Delivery webhook (
X-App-Signature).How
_resolvePayload,_resolvePayloadFromString,_loadPayloadStringand_resolvePayloadBytesreturn a named record({mimeType, payload, bytes})instead of discarding the bytes.toAPIRequestpasses them toAPIRequest.payloadBytes.decompressPayload). They arenullfor a request built in code, and when the server reads no body.payloadAsBytesreturns a copy for text bodies.payloadAsBytesfor a request built in code with a JSON MIME type: the payload is encoded as JSON, not as itstoString.Uint8List(0).Behavior change
A route's
Uint8Listparameter filled from a text body (throughAPIModule) now gets the body as received. For example, atext/plain; charset=latin1body keeps itslatin1bytes. The twoupload(text:latin1)tests inbones_api_test.dartare updated to match.Tests
test/bones_api_cov_base_test.dart:payloadAsBytesper case:MapandList),latin1text, anyString;List<int>payload, a non-text MIME type, and requests built in code (JSON and non-JSON);payloadBytesread-only, and the copy free to change;test/bones_api_cov_server_config_test.dart:payloadBytesthroughtoAPIRequest: JSON with odd spacing, invalid JSON, text,latin1, binary, empty, no body;test/bones_api_test.dart: over HTTP, a JSON body'spayloadAsByteskeeps its spacing.bones_api_cov_base_test,bones_api_cov_server_config_test,bones_api_cov_server_http_test,bones_api_test,bones_api_module_test,bones_api_platform_vm_test.Version 1.36.0 (pubspec,
BonesAPI.VERSION, CHANGELOG).🤖 Generated with Claude Code