Skip to content

Commit

Permalink
fix: Use is-gzip to determine if response is gzipped (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
terry-au authored Dec 23, 2021
1 parent 2643132 commit bce0974
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
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

0 comments on commit bce0974

Please sign in to comment.