okhttp3.Credentials 使用 ISO_8859_1 而不是 UTF-8 有什么原因吗?

Is there any reason why okhttp3.Credentials use ISO_8859_1 instead UTF-8?

我正在使用 okhttp3.Credentials 在我当前的项目中获取 Base64 字符串。我发现我在服务器上作为 Base64 字符串传递的西里尔符号存在问题,并最终发现 okhttp3.Credentials 的当前实现使用 ISO_8859_1.

在这里使用 ISO_8859_1 而不是更通用的 UTF-8 是否有深思熟虑的意图?

根据回答更新:

参考规范

The original definition of this authentication scheme failed to
specify the character encoding scheme used to convert the user-pass
into an octet sequence. In practice, most implementations chose
either a locale-specific encoding such as ISO-8859-1 ([ISO-8859-1]),
or UTF-8 ([RFC3629]). For backwards compatibility reasons, this
specification continues to leave the default encoding undefined, as
long as it is compatible with US-ASCII (mapping any US-ASCII
character to a single octet matching the US-ASCII character code).



B.3. Why not simply switch the default encoding to UTF-8?

There are sites in use today that default to a local character
encoding scheme, such as ISO-8859-1 ([ISO-8859-1]), and expect user
agents to use that encoding. Authentication on these sites will stop
working if the user agent switches to a different encoding, such as
UTF-8.

Note that sites might even inspect the User-Agent header field
([RFC7231], Section 5.5.3) to decide which character encoding scheme
to expect from the client. Therefore, they might support UTF-8 for
some user agents, but default to something else for others. User
agents in the latter group will have to continue to do what they do
today until the majority of these servers have been upgraded to
always use UTF-8.

在这里讨论https://github.com/square/okhttp/pull/3134

它是遗留的,您可以使用可选参数覆盖。