apollo-datasource-http
Advanced tools
Comparing version 0.20.0 to 0.21.0
@@ -11,2 +11,4 @@ "use strict"; | ||
const quick_lru_1 = __importDefault(require("@alloc/quick-lru")); | ||
const zlib_1 = require("zlib"); | ||
const stream_to_promise_1 = __importDefault(require("stream-to-promise")); | ||
const apollo_server_errors_1 = require("apollo-server-errors"); | ||
@@ -158,7 +160,22 @@ const url_1 = require("url"); | ||
const responseData = await this.pool.request(requestOptions); | ||
let body = await responseData.body.text(); | ||
const body = responseData.body; | ||
const headers = responseData.headers; | ||
let dataBuffer; | ||
switch (headers['content-encoding']) { | ||
case 'br': | ||
dataBuffer = await (0, stream_to_promise_1.default)(body.pipe((0, zlib_1.createBrotliDecompress)())); | ||
break; | ||
case 'gzip': | ||
case 'deflate': | ||
dataBuffer = await (0, stream_to_promise_1.default)(body.pipe((0, zlib_1.createUnzip)())); | ||
break; | ||
default: | ||
dataBuffer = await (0, stream_to_promise_1.default)(body); | ||
break; | ||
} | ||
let data = dataBuffer.toString('utf-8'); | ||
if (((_b = responseData.headers['content-type']) === null || _b === void 0 ? void 0 : _b.includes('application/json')) && | ||
body.length && | ||
typeof body === 'string') { | ||
body = JSON.parse(body); | ||
data.length && | ||
typeof data === 'string') { | ||
data = JSON.parse(data); | ||
} | ||
@@ -169,3 +186,3 @@ const response = { | ||
...responseData, | ||
body: body, | ||
body: data, | ||
}; | ||
@@ -172,0 +189,0 @@ this.onResponse(request, response); |
{ | ||
"name": "apollo-datasource-http", | ||
"version": "0.20.0", | ||
"version": "0.21.0", | ||
"author": "Dustin Deus <deusdustin@gmail.com>", | ||
@@ -57,2 +57,3 @@ "license": "MIT", | ||
"apollo-server-types": "^3.5.1", | ||
"stream-to-promise": "^3.0.0", | ||
"undici": "^4.13.0" | ||
@@ -68,2 +69,3 @@ }, | ||
"@types/sinonjs__fake-timers": "^8.1.1", | ||
"@types/stream-to-promise": "^2.2.1", | ||
"abort-controller": "^3.0.0", | ||
@@ -70,0 +72,0 @@ "apollo-datasource-rest": "^3.5.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35294
359
8
17
+ Addedstream-to-promise@^3.0.0
+ Addedany-promise@1.3.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedstream-to-array@2.3.0(transitive)
+ Addedstream-to-promise@3.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)