From 8bbc906b59a239a61406b1f5451af8ffea81cd41 Mon Sep 17 00:00:00 2001 From: Travis Staloch Date: Sun, 14 May 2023 18:48:03 -0700 Subject: [PATCH] Package: support gitlab tarball urls Allows the package manager to download gitlab tarballs from urls such as https://gitlab.com///-/archive//-.tar.gz Such http requests have headers Content-Type=application/octet-stream and Content-Disposition='attachment; filename="-.tar.gz"'. The package manager doesn't yet support these headers. This patch doesn't attempt to properly parse the content-disposition header. Instead it checks that it starts with 'attachment;' and ends with '.tar.gz"'. --- src/Package.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Package.zig b/src/Package.zig index f4593fee484413d56959fdcd3e82b6cdd08aad20..f84f0a8a1b6681d8c6d7d0737b4e15248defab71 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -510,6 +510,16 @@ fn fetchAndUnpack( // I have not checked what buffer sizes the xz decompression implementation uses // by default, so the same logic applies for buffering the reader as for gzip. try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz); + } else if (ascii.eqlIgnoreCase(content_type, "application/octet-stream")) { + // support gitlab tarball urls such as https://gitlab.com///-/archive//-.tar.gz + // whose content-disposition header is: 'attachment; filename="-.tar.gz"' + const content_disposition = req.response.headers.getFirstValue("Content-Disposition") orelse + return report.fail(dep.url_tok, "Missing 'Content-Disposition' header for Content-Type=application/octet-stream", .{}); + if (mem.startsWith(u8, content_disposition, "attachment;") and + mem.endsWith(u8, content_disposition, ".tar.gz\"")) + { + try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip); + } else return report.fail(dep.url_tok, "Unsupported 'Content-Disposition' header value: '{s}' for Content-Type=application/octet-stream", .{content_disposition}); } else { return report.fail(dep.url_tok, "Unsupported 'Content-Type' header value: '{s}'", .{content_type}); } -- 2.54.0