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

Unzipping the content before sending to the parser based on the respo… #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var _ = require('./utils')
var IS_BROWSER = typeof window === 'object' && window
var JSON_MIME = /application\/json/i
var http = resolveModule()
const zlib = require('zlib');

module.exports = HttpClient

Expand Down Expand Up @@ -81,6 +82,21 @@ function resolveModule () {

function requestWrapper (request) {
return function requester (options, cb) {
return request(mapOptions(options), mapResponse(cb))
let httpRequest = request(mapOptions(options), mapResponse(cb));
httpRequest.on('response', function(response) {
switch (response.headers['content-encoding']) {
// or, just use zlib.createUnzip() to handle both cases
case 'gzip':
console.log("gzip");
response.pipe(zlib.createGunzip()).pipe(response);
break;
case 'deflate':
response.pipe(zlib.createInflate()).pipe(response);
break;
default:
break;
}
});
return httpRequest;
}
}