std.net.curl: Fix fast-path check when encoding is "utf-8" (lower-case) (#10721)

For HTTP, the response body encoding is specified in the
"Content-Type" header, e.g.: "Content-Type: application/json;
charset=utf-8".

MDN says:

> - `charset`: Indicates the character encoding standard used.
>   The value is **case insensitive but lowercase is preferred**.

However, `_decodeContent` was comparing the encoding with the exact
string "UTF-8", which causes most HTTP requests to go through the slow
path.

Fix this by using `icmp`, like elsewhere in the module for
case-insensitive string comparisons.
This commit is contained in:
Vladimir Panteleev 2025-03-29 10:59:08 +00:00 committed by GitHub
parent 1de571c710
commit 94903c884a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1226,9 +1226,10 @@ private auto _decodeContent(T)(ubyte[] content, string encoding)
{
import std.exception : enforce;
import std.format : format;
import std.uni : icmp;
// Optimally just return the utf8 encoded content
if (encoding == "UTF-8")
if (icmp(encoding, "UTF-8") == 0)
return cast(char[])(content);
// The content has to be re-encoded to utf8