From b94ae92c6e6c3897910448eec4589c45c349b6b9 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 3 Jun 2025 13:28:29 -0700 Subject: [PATCH] Extend getArchive to allow headers to be passed in to the HTTP request. This can be used to get a gzipped tar by passing in Accept-Encoding: gzip. --- lib/container.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/container.js b/lib/container.js index 38279bf..353aa23 100644 --- a/lib/container.js +++ b/lib/container.js @@ -887,13 +887,18 @@ Container.prototype.copy = function(opts, callback) { /** * getArchive - * @param {Object} opts Archive options, like 'path' + * @param {Object} opts Archive options, like 'path'. As a special case, + * allows `headers`, which will set the HTTP headers used on the request. + * Use this to set `headers: { 'Accept-Encoding': 'gzip' }` to get a gzipped + * tar. * @param {Function} callback Callback with stream. */ Container.prototype.getArchive = function(opts, callback) { var self = this; var args = util.processArgs(opts, callback, this.defaultOptions.getArchive); + const { headers, ...otherOpts } = args.opts; + var optsf = { path: '/containers/' + this.id + '/archive?', method: 'GET', @@ -905,7 +910,8 @@ Container.prototype.getArchive = function(opts, callback) { 404: 'no such container', 500: 'server error' }, - options: args.opts + options: otherOpts, + headers, }; if(args.callback === undefined) {