@middy/http-content-encoding 3.0.0-alpha.2 → 3.0.0-alpha.6
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.
- package/index.js +16 -4
- package/package.json +6 -5
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Readable, Writable
|
|
1
|
+
import stream, { Readable, Writable } from 'stream';
|
|
2
|
+
import eventEmitter from 'events';
|
|
2
3
|
import { promisify } from 'util';
|
|
3
4
|
import { createBrotliCompress, createGzip, createDeflate } from 'zlib';
|
|
4
5
|
import { normalizeHttpResponse } from '@middy/util';
|
|
5
|
-
const pipeline = promisify(pipelineCallback);
|
|
6
6
|
const contentEncodingStreams = {
|
|
7
7
|
br: (opts = {}) => createBrotliCompress(opts),
|
|
8
8
|
gzip: (opts = {}) => createGzip(opts),
|
|
@@ -19,6 +19,7 @@ const httpContentEncodingMiddleware = opts => {
|
|
|
19
19
|
const options = { ...defaults,
|
|
20
20
|
...opts
|
|
21
21
|
};
|
|
22
|
+
const supportedContentEncodings = Object.keys(contentEncodingStreams);
|
|
22
23
|
|
|
23
24
|
const httpContentEncodingMiddlewareAfter = async request => {
|
|
24
25
|
normalizeHttpResponse(request);
|
|
@@ -30,7 +31,7 @@ const httpContentEncodingMiddleware = opts => {
|
|
|
30
31
|
response
|
|
31
32
|
} = request;
|
|
32
33
|
|
|
33
|
-
if (!preferredEncoding ||
|
|
34
|
+
if (response.isBase64Encoded || !preferredEncoding || !supportedContentEncodings.includes(preferredEncoding)) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -85,6 +86,17 @@ const httpContentEncodingMiddleware = opts => {
|
|
|
85
86
|
};
|
|
86
87
|
};
|
|
87
88
|
|
|
88
|
-
const isReadableStream = stream =>
|
|
89
|
+
const isReadableStream = stream => {
|
|
90
|
+
return stream instanceof eventEmitter && stream.readable !== false;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const polyfillPipelinePromise = () => {
|
|
94
|
+
if (process.version < 'v15.0.0') {
|
|
95
|
+
return promisify(stream.pipeline);
|
|
96
|
+
} else {
|
|
97
|
+
return stream.promises.pipeline;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
89
100
|
|
|
101
|
+
const pipeline = polyfillPipelinePromise();
|
|
90
102
|
export default httpContentEncodingMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-content-encoding",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.6",
|
|
4
4
|
"description": "Http content encoding middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "npm run test:unit",
|
|
21
|
-
"test:unit": "ava"
|
|
21
|
+
"test:unit": "ava",
|
|
22
|
+
"test:benchmark": "node __benchmarks__/index.js"
|
|
22
23
|
},
|
|
23
24
|
"license": "MIT",
|
|
24
25
|
"keywords": [
|
|
@@ -50,10 +51,10 @@
|
|
|
50
51
|
},
|
|
51
52
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@middy/util": "^3.0.0-alpha.
|
|
54
|
+
"@middy/util": "^3.0.0-alpha.6"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@middy/core": "^3.0.0-alpha.
|
|
57
|
+
"@middy/core": "^3.0.0-alpha.6"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "176660ed3e0716d6bfb635c77251b301e0e24720"
|
|
59
60
|
}
|