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

Closed
opened 2025-11-02 07:06:30 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @0x6d61726b on GitHub (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:
99b7af6fc8/modules/context/context.go (L359)
99b7af6fc8/modules/context/context.go (L324)

Originally created by @0x6d61726b on GitHub (Jan 28, 2021). - Gitea version: 1.14.0+dev-629-gd1353e1f7 - Operating system: Windows 10 - Can you reproduce the bug at https://try.gitea.io: - [X] Yes: https://try.gitea.io/api/v1/version - [ ] No ## 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](https://www.w3.org/International/articles/http-charset/index), which is referring to the [IANA](http://www.iana.org/assignments/character-sets) 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: https://github.com/go-gitea/gitea/blob/99b7af6fc89687ee74ca938b9a3f07bf8acc79dd/modules/context/context.go#L359 https://github.com/go-gitea/gitea/blob/99b7af6fc89687ee74ca938b9a3f07bf8acc79dd/modules/context/context.go#L324
GiteaMirror added the type/bug label 2025-11-02 07:06:30 -06:00
Author
Owner

@0x6d61726b commented on GitHub (Jan 29, 2021):

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

@0x6d61726b commented on GitHub (Jan 29, 2021): Thanks a lot for providing the fix so quickly. I have tested and verified it working with Gitea `1.14.0+dev-642-g0e0424c8e`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6784