Commit 8bbc906b59

Travis Staloch <twostepted@gmail.com>
2023-05-15 03:48:03
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 parent 4ba61a2
Changed files (1)
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/<namespace>/<project>/-/archive/<sha>/<project>-<sha>.tar.gz
+            // whose content-disposition header is: 'attachment; filename="<project>-<sha>.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});
         }