Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use is-gzip to determine if response is gzipped #93

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/assets/sitemapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
},
"dependencies": {
"got": "^11.8.0",
"is-gzip": "2.0.0",
"p-limit": "^3.1.0",
"xml2js": "^0.4.23"
}
Expand Down
19 changes: 3 additions & 16 deletions src/assets/sitemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import { parseStringPromise } from 'xml2js';
import got from 'got';
import zlib from 'zlib';
import Url from 'url';
import path from 'path';
import pLimit from 'p-limit';
import isGzip from 'is-gzip';

/**
* @typedef {Object} Sitemapper
Expand Down Expand Up @@ -154,7 +153,7 @@ export default class Sitemapper {

try {
// create a request Promise with the url and request options
const requester = got(url, requestOptions);
const requester = got.get(url, requestOptions);

// initialize the timeout method based on the URL, and pass the request object.
this.initializeTimeout(url, requester);
Expand All @@ -170,7 +169,7 @@ export default class Sitemapper {

let responseBody;

if (this.isGzip(url)) {
if (isGzip(response.rawBody)) {
responseBody = await this.decompressResponseBody(response.body);
} else {
responseBody = response.body;
Expand Down Expand Up @@ -341,18 +340,6 @@ export default class Sitemapper {
return callback(err, sites);
}

/**
* Check to see if the url is a gzipped url
*
* @param {string} url - url to query
* @returns {Boolean}
*/
isGzip(url) {
const parsed = Url.parse(url);
const ext = path.extname(parsed.path);
return ext === '.gz';
}

/**
* Decompress the gzipped response body using zlib.gunzip
*
Expand Down