Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON in RPC is not being sent with the correct Content-Type headers (even other custom headers not working) #3814

Open
DDuran19 opened this issue Jan 9, 2025 · 4 comments
Labels

Comments

@DDuran19
Copy link

DDuran19 commented Jan 9, 2025

What version of Hono are you using?

4.6.16

What runtime/platform is your app running on? (with version if possible)

local - nodejs. remote - cloudflare workers

What steps can reproduce the bug?

Create an endpoint and use zValidator("json", someValidator)
create an RPC that client can use. use hc
access the endpoint and pass in a json body
check the network tab and you would see the content-type is text/plain instead of application/json

What is the expected behavior?

headers should be Content-Type = application/json

What do you see instead?

text/plain

Additional information

client rpc
image

endpoint:
image

error returned by zValidator cause he's not able to parse the body correctly.
image

correct payload was sent
image

incorrect headers were set
image

@DDuran19 DDuran19 added the triage label Jan 9, 2025
@DDuran19
Copy link
Author

DDuran19 commented Jan 9, 2025

I think the main problem here is in the implementation of hc. I am not sure, I can't seem to figure it out I've been having this trouble for a few months now. The JSON used to work but I don't remember which update broke it.

@devpapi0891
Copy link

Up

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jan 9, 2025

I cannot reproduce this.
The server-side validator does not affect the client's behavior, so the cause must be the client.

If you don't mind, I'd like to know more about the situation. (for example, initialization code)
I will try a few things.

@EdamAme-x
Copy link
Contributor

Example Code

import { hc } from "./client";

const c = hc("http://localhost", {
    fetch: console.log
})

c.api.forms.$post({
    json: {
        name: "a",
        description: "b",
        entity: [],
        public: ""
    }
})

Log

http://localhost/api/forms {
  body: "{\"name\":\"a\",\"description\":\"b\",\"entity\":[],\"public\":\"\"}",
  method: "POST",
  headers: Headers {
    "content-type": "application/json",
  },
}

On Node, Deno, Bun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants