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

Better Content-Type detection in zhttp #95

Closed
1 task done
nDmitry opened this issue Feb 20, 2025 · 1 comment
Closed
1 task done

Better Content-Type detection in zhttp #95

nDmitry opened this issue Feb 20, 2025 · 1 comment

Comments

@nDmitry
Copy link

nDmitry commented Feb 20, 2025

Before you begin

  • I have read the FAQ and my issue was not answered there

What version of Zog are you using

v0.16.0

Describe the bug

Some HTTP clients send values for Content-Type headers with a charset appended to it. E.g. axios (JS HTTP library) will send this header by default: Content-Type: application/json;charset=utf-8, which zhttp cannot detect using its simple switch statement. While it can be changed to just application/json on the client side, a more robust content-type detection can be implemented on Zog's part (using strings.Contains?).

To Reproduce

I think looking in the source code should be enough. Otherwise it can be reproduced using any HTTP client against a server using zhttp, just send this header: Content-Type: application/json;charset=utf-8.

Expected behavior

zhttp should detect a more complex Content-Type values with any directive specified after a semicolon following the content type.

Additional context

charset is an allowed directive in Content-Type header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type#directives

@Oudwins
Copy link
Owner

Oudwins commented Feb 20, 2025

Good catch. Thank you.

@Oudwins Oudwins closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants