authorgravatar for joelgustafson@protonmail.comJoel Gustafson <joelgustafson@protonmail.com> 2024-01-09 15:16:59-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-09 20:16:59+00:00
logdbdee2d53cf22be8bcc9031c1c15a58ce530b131
tree589e93244a9b53663328e34bff26fd4746539052
parent60094cc3fc979df0928c412c9fded457172f2060
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

ignore charset and boundary directives in content-type headers when fetching dependencies


1 files changed, 11 insertions(+), 7 deletions(-)

src/Package/Fetch.zig+11-7
......@@ -962,23 +962,27 @@ fn unpackResource(
962962 const content_type = req.response.headers.getFirstValue("Content-Type") orelse
963963 return f.fail(f.location_tok, try eb.addString("missing 'Content-Type' header"));
964964
965 if (ascii.eqlIgnoreCase(content_type, "application/x-tar"))
965 // Extract the MIME type, ignoring charset and boundary directives
966 const mime_type_end = std.mem.indexOf(u8, content_type, ";") orelse content_type.len;
967 const mime_type = content_type[0..mime_type_end];
968
969 if (ascii.eqlIgnoreCase(mime_type, "application/x-tar"))
966970 break :ft .tar;
967971
968 if (ascii.eqlIgnoreCase(content_type, "application/gzip") or
969 ascii.eqlIgnoreCase(content_type, "application/x-gzip") or
970 ascii.eqlIgnoreCase(content_type, "application/tar+gzip"))
972 if (ascii.eqlIgnoreCase(mime_type, "application/gzip") or
973 ascii.eqlIgnoreCase(mime_type, "application/x-gzip") or
974 ascii.eqlIgnoreCase(mime_type, "application/tar+gzip"))
971975 {
972976 break :ft .@"tar.gz";
973977 }
974978
975 if (ascii.eqlIgnoreCase(content_type, "application/x-xz"))
979 if (ascii.eqlIgnoreCase(mime_type, "application/x-xz"))
976980 break :ft .@"tar.xz";
977981
978 if (ascii.eqlIgnoreCase(content_type, "application/zstd"))
982 if (ascii.eqlIgnoreCase(mime_type, "application/zstd"))
979983 break :ft .@"tar.zst";
980984
981 if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) {
985 if (!ascii.eqlIgnoreCase(mime_type, "application/octet-stream")) {
982986 return f.fail(f.location_tok, try eb.printString(
983987 "unrecognized 'Content-Type' header: '{s}'",
984988 .{content_type},