authorgravatar for twostepted@gmail.comTravis Staloch <twostepted@gmail.com> 2023-05-14 18:48:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-15 22:44:32-07:00
log8bbc906b59a239a61406b1f5451af8ffea81cd41
tree65fbc7659269829c5bfa8ffa28491a6cde0b1104
parent4ba61a219136ccf81d8dee6317af597244c0db1e

Package: support gitlab tarball urls

Allows the package manager to download gitlab tarballs from urls such as https://gitlab.com/<namespace>/<project>/-/archive/<sha>/<project>-<sha>.tar.gz Such http requests have headers Content-Type=application/octet-stream and Content-Disposition='attachment; filename="<project>-<sha>.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"'.

1 files changed, 10 insertions(+), 0 deletions(-)

src/Package.zig+10
...@@ -510,6 +510,16 @@ fn fetchAndUnpack(...@@ -510,6 +510,16 @@ fn fetchAndUnpack(
510 // I have not checked what buffer sizes the xz decompression implementation uses510 // I have not checked what buffer sizes the xz decompression implementation uses
511 // by default, so the same logic applies for buffering the reader as for gzip.511 // by default, so the same logic applies for buffering the reader as for gzip.
512 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);512 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);
513 } else if (ascii.eqlIgnoreCase(content_type, "application/octet-stream")) {
514 // support gitlab tarball urls such as https://gitlab.com/<namespace>/<project>/-/archive/<sha>/<project>-<sha>.tar.gz
515 // whose content-disposition header is: 'attachment; filename="<project>-<sha>.tar.gz"'
516 const content_disposition = req.response.headers.getFirstValue("Content-Disposition") orelse
517 return report.fail(dep.url_tok, "Missing 'Content-Disposition' header for Content-Type=application/octet-stream", .{});
518 if (mem.startsWith(u8, content_disposition, "attachment;") and
519 mem.endsWith(u8, content_disposition, ".tar.gz\""))
520 {
521 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip);
522 } else return report.fail(dep.url_tok, "Unsupported 'Content-Disposition' header value: '{s}' for Content-Type=application/octet-stream", .{content_disposition});
513 } else {523 } else {
514 return report.fail(dep.url_tok, "Unsupported 'Content-Type' header value: '{s}'", .{content_type});524 return report.fail(dep.url_tok, "Unsupported 'Content-Type' header value: '{s}'", .{content_type});
515 }525 }