Skip to content

/api/v1 returns application/json; charset=utf8 instead of utf-8 #14511

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

Closed
1 of 2 tasks
0x6d61726b opened this issue Jan 28, 2021 · 1 comment · Fixed by #14514
Closed
1 of 2 tasks

/api/v1 returns application/json; charset=utf8 instead of utf-8 #14511

0x6d61726b opened this issue Jan 28, 2021 · 1 comment · Fixed by #14514
Labels

Comments

@0x6d61726b
Copy link

0x6d61726b commented Jan 28, 2021

Description

When decoding the response from https://try.gitea.io/api/v1/version with .NET code _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); an exception is thrown because the charset utf8 is invalid. The Gitea test server responds with the following HTTP headers:

Content-Length: 40
Content-Type: application/json; charset=utf8

According to the W3C, which is referring to the IANA the charset is specified as UTF-8. When manually modifying the received header to application/json; charset=utf-8, decoding works fine and no exception is thrown.

When working with my local test server, which is behind a reverse-proxy, the API is also working fine, because the proxy is "sanitizing" the character set:

content-type: application/json; charset=UTF-8
content-encoding: gzip

If you agree with my observation that the charset should be UTF-8 or utf-8 (containing a dash), please consider changing the character set for one of the upcoming releases to be standard compliant.

Without any further knowledge about Gitea or golang, two of the possibly affected locations are:

ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf8")

ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf8")

@0x6d61726b
Copy link
Author

Thanks a lot for providing the fix so quickly. I have tested and verified it working with Gitea 1.14.0+dev-642-g0e0424c8e.

@go-gitea go-gitea locked and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants