Skip to content

Web Fetch: Request.text() / Request.json() / Request.arrayBuffer() return 0 instead of the body #1688

Description

@proggeramlug

Scope

new Request(url, { body }).text() / .json() / .arrayBuffer() return 0 instead of the request body under Perry-native compile. req.method / req.url / req.headers work (#1649); only the body-consuming methods are unimplemented.

This blocks the Hono app.post('/api/echo', async c => c.json({ body: await c.req.json() })) route in the #1655 acceptance — c.req.json() reads the request body via req.text()/the body stream.

Repro (Perry @ main 7371549)

const req = new Request('http://localhost/x', {
  method: 'POST', headers: { 'content-type': 'application/json' }, body: '{"x":1}',
})
console.log('method', req.method)        // POST  ✅
console.log('text', await req.text())    // 0     ❌ (expected '{"x":1}')
console.log('json', JSON.stringify(await req.json()))  // 0  ❌ (expected {"x":1})

Observed: text and json both yield 0.
Expected (Node): {"x":1} / {"x":1}.

Note

js_request_get_body already stores the body string (used by the req.body property getter); the gap is that Request.text() / .json() / .arrayBuffer() aren't wired to it (the typed module=="Request" codegen arm in lower_call/options/fetch.rs handles url/method/body/headers properties but no body methods, and there's no untyped dispatch_request_method). Mirror the existing Response .text()/.json() path.

Related

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