| ... | @@ -5,6 +5,7 @@ const std = @import("std"); | ... | @@ -5,6 +5,7 @@ const std = @import("std"); |
| 5 | const fs = std.fs; | 5 | const fs = std.fs; |
| 6 | const mem = std.mem; | 6 | const mem = std.mem; |
| 7 | const Allocator = mem.Allocator; | 7 | const Allocator = mem.Allocator; |
| | 8 | const ascii = std.ascii; |
| 8 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 9 | const log = std.log.scoped(.package); | 10 | const log = std.log.scoped(.package); |
| 10 | const main = @import("main.zig"); | 11 | const main = @import("main.zig"); |
| ... | @@ -488,11 +489,16 @@ fn fetchAndUnpack( | ... | @@ -488,11 +489,16 @@ fn fetchAndUnpack( |
| 488 | try req.start(); | 489 | try req.start(); |
| 489 | try req.wait(); | 490 | try req.wait(); |
| 490 | | 491 | |
| 491 | if (mem.endsWith(u8, uri.path, ".tar.gz")) { | 492 | const content_type = req.response.headers.getFirstValue("Content-Type") orelse |
| | 493 | return report.fail(dep.url_tok, "missing Content-Type for '{s}'", .{uri.path}); |
| | 494 | |
| | 495 | if (ascii.eqlIgnoreCase(content_type, "application/gzip") or |
| | 496 | ascii.eqlIgnoreCase(content_type, "application/x-gzip")) |
| | 497 | { |
| 492 | // I observed the gzip stream to read 1 byte at a time, so I am using a | 498 | // I observed the gzip stream to read 1 byte at a time, so I am using a |
| 493 | // buffered reader on the front of it. | 499 | // buffered reader on the front of it. |
| 494 | try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip); | 500 | try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip); |
| 495 | } else if (mem.endsWith(u8, uri.path, ".tar.xz")) { | 501 | } else if (ascii.eqlIgnoreCase(content_type, "application/x-xz")) { |
| 496 | // I have not checked what buffer sizes the xz decompression implementation uses | 502 | // I have not checked what buffer sizes the xz decompression implementation uses |
| 497 | // by default, so the same logic applies for buffering the reader as for gzip. | 503 | // by default, so the same logic applies for buffering the reader as for gzip. |
| 498 | try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz); | 504 | try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz); |