Skip to content

Request body methods (json/text/arrayBuffer) not callable as a value / via computed key (typeof is 'object'/'undefined') #1698

Closed

Description

@proggeramlug

Scope

Request's body methods work when called directly (req.json() — #1688), but fail when accessed as a value or via a computed key:

const req = new Request('http://localhost/x', {
  method: 'POST', headers: { 'content-type': 'application/json' }, body: '{"x":1}',
})
console.log(typeof req.json)            // perry: 'object'    | node: 'function'
const key = 'json'
console.log(typeof (req as any)[key])   // perry: 'undefined' | node: 'function'
console.log(await (req as any)[key]())  // perry: null/throws | node: {"x":1}

This blocks Hono's c.req.json() end-to-end (#1655): Hono's HonoRequest.#cachedBody does raw[key]() (computed-key call), which yields undefined → throws value is not a function. The POST /api/echo route reaches the handler (status 200) but await c.req.json() throws.

Likely fix

Expose Request.json / .text / .arrayBuffer (and .blob/.formData) as bound-method values the way the same gap was closed for native-module methods (#1343 / #1367 / #1368 / #1380) — so typeof req.json === 'function' and req['json']() dispatches. There's likely no untyped dispatch_request_method for the body methods (the typed codegen module=="Request" arm only handles url/method/body/headers properties + the direct .json()/.text() calls added in #1688).

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions