Return ASCII header values as their own ByteString

Converting a header value to a ByteString read it one UTF-16 code unit at a
time through scr_str_char_code_at into a fresh buffer. An all-ASCII value,
which nearly every header is, is already its own ByteString, so it is now
returned as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Malte Ubl
2026-10-23 00:29:28 -07:00
co-authored by Claude Opus 5.5
parent 80f0bfada2
commit bcd506fc8b
+4
View File
@@ -3287,6 +3287,10 @@ static bool sf_header_value_ok(const ScrStr *value) {
}
static ScrStr *sf_header_value_bytestring(ScrStr *value) {
/* An ASCII value is its own ByteString: each byte is one UTF-16 unit. */
size_t ascii = 0;
while (ascii < value->len && (unsigned char)value->data[ascii] < 0x80) ascii++;
if (ascii == value->len) return scr_str_retain(value);
size_t len = (size_t)scr_str_utf16_len(value);
char *bytes = malloc(len ? len : 1);
if (!bytes) sf_oom();