@whatwg-node/node-fetch 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +17 -1
  2. package/index.mjs +17 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -9,6 +9,7 @@ const http = require('http');
9
9
  const https = require('https');
10
10
  const stream = require('stream');
11
11
  const url = require('url');
12
+ const zlib = require('zlib');
12
13
  const events = require('@whatwg-node/events');
13
14
  const busboy = _interopDefault(require('busboy'));
14
15
  const FastQuerystring = _interopDefault(require('fast-querystring'));
@@ -1323,6 +1324,21 @@ function fetchPonyfill(info, init) {
1323
1324
  headers: nodeHeaders,
1324
1325
  });
1325
1326
  nodeRequest.once('response', nodeResponse => {
1327
+ let responseBody = nodeResponse;
1328
+ const contentEncoding = nodeResponse.headers['content-encoding'];
1329
+ switch (contentEncoding) {
1330
+ case 'x-gzip':
1331
+ case 'gzip':
1332
+ responseBody = nodeResponse.pipe(zlib.createGunzip());
1333
+ break;
1334
+ case 'x-deflate':
1335
+ case 'deflate':
1336
+ responseBody = nodeResponse.pipe(zlib.createInflate());
1337
+ break;
1338
+ case 'br':
1339
+ responseBody = nodeResponse.pipe(zlib.createBrotliDecompress());
1340
+ break;
1341
+ }
1326
1342
  if (nodeResponse.headers.location) {
1327
1343
  if (fetchRequest.redirect === 'error') {
1328
1344
  const redirectError = new Error('Redirects are not allowed');
@@ -1342,7 +1358,7 @@ function fetchPonyfill(info, init) {
1342
1358
  }
1343
1359
  }
1344
1360
  const responseHeaders = nodeResponse.headers;
1345
- const ponyfillResponse = new PonyfillResponse(nodeResponse, {
1361
+ const ponyfillResponse = new PonyfillResponse(responseBody, {
1346
1362
  status: nodeResponse.statusCode,
1347
1363
  statusText: nodeResponse.statusMessage,
1348
1364
  headers: responseHeaders,
package/index.mjs CHANGED
@@ -3,6 +3,7 @@ import { STATUS_CODES, request as request$1 } from 'http';
3
3
  import { request } from 'https';
4
4
  import { Readable } from 'stream';
5
5
  import { fileURLToPath } from 'url';
6
+ import { createBrotliDecompress, createInflate, createGunzip } from 'zlib';
6
7
  import { EventTarget, CustomEvent } from '@whatwg-node/events';
7
8
  import busboy from 'busboy';
8
9
  import FastQuerystring from 'fast-querystring';
@@ -1317,6 +1318,21 @@ function fetchPonyfill(info, init) {
1317
1318
  headers: nodeHeaders,
1318
1319
  });
1319
1320
  nodeRequest.once('response', nodeResponse => {
1321
+ let responseBody = nodeResponse;
1322
+ const contentEncoding = nodeResponse.headers['content-encoding'];
1323
+ switch (contentEncoding) {
1324
+ case 'x-gzip':
1325
+ case 'gzip':
1326
+ responseBody = nodeResponse.pipe(createGunzip());
1327
+ break;
1328
+ case 'x-deflate':
1329
+ case 'deflate':
1330
+ responseBody = nodeResponse.pipe(createInflate());
1331
+ break;
1332
+ case 'br':
1333
+ responseBody = nodeResponse.pipe(createBrotliDecompress());
1334
+ break;
1335
+ }
1320
1336
  if (nodeResponse.headers.location) {
1321
1337
  if (fetchRequest.redirect === 'error') {
1322
1338
  const redirectError = new Error('Redirects are not allowed');
@@ -1336,7 +1352,7 @@ function fetchPonyfill(info, init) {
1336
1352
  }
1337
1353
  }
1338
1354
  const responseHeaders = nodeResponse.headers;
1339
- const ponyfillResponse = new PonyfillResponse(nodeResponse, {
1355
+ const ponyfillResponse = new PonyfillResponse(responseBody, {
1340
1356
  status: nodeResponse.statusCode,
1341
1357
  statusText: nodeResponse.statusMessage,
1342
1358
  headers: responseHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {