From 8fc08260898d9b923681377fbebb6027d981419d Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 22 Sep 2022 13:00:37 +0200 Subject: [PATCH] fix: disable compression --- index.js | 15 ++++++++------- test/index.js | 9 +++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5636870..839c378 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,12 @@ const pReflect = require('p-reflect') const { URL } = require('url') -const got = require('got') + +const got = require('got').extend({ + decompress: false, + responseType: 'buffer', + retry: 0 +}) const mergeResponse = (responseOrigin = {}, responseDestination = {}) => ({ statusMessage: 'Not Found', @@ -12,12 +17,8 @@ const mergeResponse = (responseOrigin = {}, responseDestination = {}) => ({ ...responseDestination }) -const reachableUrl = async (url, opts = {}) => { - const req = got(url, { - ...opts, - retry: 0, - responseType: 'buffer' - }) +const reachableUrl = async (url, opts) => { + const req = got(url, opts) const redirectStatusCodes = [] const redirectUrls = [] diff --git a/test/index.js b/test/index.js index 286d666..21a3cdd 100644 --- a/test/index.js +++ b/test/index.js @@ -160,3 +160,12 @@ test('fast unreachable request resolution', async t => { t.is(res.statusCode, 404) t.is(res.statusMessage.toLowerCase(), 'not found') }) + +test('header `content-length` is present', async t => { + const url = 'https://cdn-microlink.vercel.app/file-examples/file_example_CSV_5000.csv' + const res = await reachableUrl(url) + t.is(res.url, url) + t.is(200, res.statusCode) + t.is(res.statusMessage, 'OK') + t.truthy(res.headers['content-length']) +})