aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Gustafson <joelgustafson@protonmail.com>2024-01-09 15:16:59 -0500
committerGitHub <noreply@github.com>2024-01-09 20:16:59 +0000
commitdbdee2d53cf22be8bcc9031c1c15a58ce530b131 (patch)
tree589e93244a9b53663328e34bff26fd4746539052 /src
parent60094cc3fc979df0928c412c9fded457172f2060 (diff)
downloadzig-dbdee2d53cf22be8bcc9031c1c15a58ce530b131.tar.gz
zig-dbdee2d53cf22be8bcc9031c1c15a58ce530b131.zip
ignore charset and boundary directives in content-type headers when fetching dependencies
Diffstat (limited to 'src')
-rw-r--r--src/Package/Fetch.zig18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig
index 514d967a48..bdd13e315f 100644
--- a/src/Package/Fetch.zig
+++ b/src/Package/Fetch.zig
@@ -962,23 +962,27 @@ fn unpackResource(
const content_type = req.response.headers.getFirstValue("Content-Type") orelse
return f.fail(f.location_tok, try eb.addString("missing 'Content-Type' header"));
- if (ascii.eqlIgnoreCase(content_type, "application/x-tar"))
+ // Extract the MIME type, ignoring charset and boundary directives
+ const mime_type_end = std.mem.indexOf(u8, content_type, ";") orelse content_type.len;
+ const mime_type = content_type[0..mime_type_end];
+
+ if (ascii.eqlIgnoreCase(mime_type, "application/x-tar"))
break :ft .tar;
- if (ascii.eqlIgnoreCase(content_type, "application/gzip") or
- ascii.eqlIgnoreCase(content_type, "application/x-gzip") or
- ascii.eqlIgnoreCase(content_type, "application/tar+gzip"))
+ if (ascii.eqlIgnoreCase(mime_type, "application/gzip") or
+ ascii.eqlIgnoreCase(mime_type, "application/x-gzip") or
+ ascii.eqlIgnoreCase(mime_type, "application/tar+gzip"))
{
break :ft .@"tar.gz";
}
- if (ascii.eqlIgnoreCase(content_type, "application/x-xz"))
+ if (ascii.eqlIgnoreCase(mime_type, "application/x-xz"))
break :ft .@"tar.xz";
- if (ascii.eqlIgnoreCase(content_type, "application/zstd"))
+ if (ascii.eqlIgnoreCase(mime_type, "application/zstd"))
break :ft .@"tar.zst";
- if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) {
+ if (!ascii.eqlIgnoreCase(mime_type, "application/octet-stream")) {
return f.fail(f.location_tok, try eb.printString(
"unrecognized 'Content-Type' header: '{s}'",
.{content_type},