hono binary response is corrupted via `c.body(bindata)`
What version of Hono are you using?
4.6.4
What runtime/platform is your app running on?
Cloudflare Worker
What steps can reproduce the bug?
schema is the protobuf schema i.e. AccountSchema
data is the generated protobuf object i.e. Account{...}
This will corrupting the binary send back or it does not sending anything would match more here it is not throw any error ...
import { toBinary } from "@bufbuild/protobuf";
//...
c.header("Content-Type", "application/protobuf");
return c.body(toBinary(schema, data));
but this works:
import { toBinary } from "@bufbuild/protobuf";
//...
c.header("Content-Type", "application/protobuf");
const protoData: Uint8Array = toBinary(schema, data)
return new Response(protoData, { status: 200, headers: c.res.headers });
What is the expected behavior?
c.body should send the data it get without any changes (https://developer.mozilla.org/en-US/docs/Web/API/Response/Response) maybe export type Data = string | ArrayBuffer | ReadableStream is wrong?
like with new Response in my example
What do you see instead?
I don't get the data back - its empty response or it has trunticated the body I'm not sure, can't debug it right now.
Additional information
No response
Hi @Dexus
Thanks for the issue. Basically,c.body should support only Data which the type defines. But I think it could support other types like ArrayBufferView, which you tried. And it works well with the following example:
import { Hono } from 'hono'
const app = new Hono()
app.get('/', (c) => {
const data = new Uint8Array([72, 101, 108, 108, 111])
return c.body(data, {
headers: {
'Content-Type': 'text/plain',
},
})
})
export default app
If you think it's a bug, can you share a minimal project to reproduce it? It's better not to use @bufbuild/protobuf.
I think its a bug, because its not throw a error on the toBinary and the output match the Uint8Array in my test case but the response is not comming, its empty
@Dexus Can you share a minimal project to reproduce it?
I'll close this issue since there has been no response for a while.