Skip to content

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

Closed
@0x6d61726b

Description

@0x6d61726b

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions