Skip to content

Commit 2a55ea3

Browse files
committed
docs(spec): IHttpRequest.body TSDoc states what a handler reads and that the read may refuse
The parsed JSON or form body, `{}` when there is none; a transport may throw from the read for a body it cannot parse or a media type it does not read, and the standard transport answers 400 INVALID_REQUEST itself; a handler that needs the bytes reads rawBody(). TSDoc only, no type change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KNNm3SRPyw288E5DT4qVGx
1 parent e246f06 commit 2a55ea3

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/spec": patch
3+
---
4+
5+
docs(spec): `IHttpRequest.body`'s TSDoc says what a handler reads, and that reading it may refuse
6+
7+
Clause-②: no
8+
9+
- **What it is.** The parsed JSON document for `application/json`, or the parsed fields of a `multipart/form-data` or `application/x-www-form-urlencoded` form; `{}` when the request carries no body.
10+
- **It may refuse.** An implementation that cannot parse the body, or does not read its media type, throws from the read instead of handing over an invented value. The standard transport (`@objectstack/plugin-hono-server`) does, and answers 400 `INVALID_REQUEST` itself, replacing whatever the handler wrote. So a handler must not catch the refusal and carry on.
11+
- **Raw bytes.** A handler that needs them reads `rawBody()` and never reads `body`.
12+
- **Unchanged:** the type (`body?: any`), every other member, and every runtime behaviour. This is prose in the shipped `.d.ts` only.

‎packages/spec/src/contracts/http-server.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,23 @@ export interface IHttpRequest {
2020
params: Record<string, string>;
2121
/** Request query parameters */
2222
query: Record<string, string | string[]>;
23-
/** Request body (parsed — JSON or form data when applicable) */
23+
/**
24+
* Request body, parsed by its declared content type: the parsed JSON
25+
* document for `application/json`, or the parsed fields of a form
26+
* (`multipart/form-data`, `application/x-www-form-urlencoded`). `{}` when
27+
* the request carries no body.
28+
*
29+
* Reading it may REFUSE: an implementation that cannot parse the body, or
30+
* that does not read the body's media type, throws from the read rather
31+
* than hand over an invented value. The standard transport
32+
* (`@objectstack/plugin-hono-server`) does, and answers the request itself
33+
* with 400 `INVALID_REQUEST`, replacing whatever the handler wrote; so a
34+
* handler must not catch the refusal and carry on, because anything it
35+
* does after the catch acts on a request that has already been refused.
36+
*
37+
* A handler that needs the raw bytes (a file upload, a media type not
38+
* listed above) reads {@link rawBody} and never reads `body`.
39+
*/
2440
body?: any;
2541
/** Request headers */
2642
headers: Record<string, string | string[]>;

0 commit comments

Comments
 (0)