Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Commit 4def22e

Browse files
Merge pull request #262 from adobe/helix-fetch-v2
Migrate to helix-fetch and re-enable HTTP/2
2 parents 4fea832 + 95251ed commit 4def22e

File tree

8 files changed

+958
-961
lines changed

8 files changed

+958
-961
lines changed

package-lock.json

Lines changed: 906 additions & 911 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,26 @@
3232
},
3333
"homepage": "https://github.com/adobe/helix-data-embed#readme",
3434
"dependencies": {
35-
"@adobe/helix-epsagon": "1.5.6",
36-
"@adobe/helix-fetch": "1.9.2",
35+
"@adobe/helix-epsagon": "1.5.8",
36+
"@adobe/helix-fetch": "2.1.3",
3737
"@adobe/helix-onedrive-support": "3.1.6",
38-
"@adobe/helix-shared": "7.19.1",
39-
"@adobe/helix-status": "9.0.0",
38+
"@adobe/helix-shared": "7.19.5",
39+
"@adobe/helix-status": "9.0.2",
4040
"@adobe/openwhisk-action-logger": "2.3.1",
4141
"@adobe/openwhisk-action-utils": "4.4.0",
4242
"@flighter/a1-notation": "1.0.7",
4343
"googleapis": "67.0.0",
44-
"node-fetch": "2.6.1",
4544
"rss-parser": "3.11.0"
4645
},
4746
"devDependencies": {
4847
"@adobe/eslint-config-helix": "1.1.3",
49-
"@adobe/helix-deploy": "1.18.0",
50-
"@adobe/helix-ops": "1.12.3",
48+
"@adobe/helix-deploy": "3.0.14",
49+
"@adobe/helix-ops": "2.0.10",
5150
"@adobe/helix-testutils": "0.4.2",
5251
"@semantic-release/changelog": "5.0.1",
5352
"@semantic-release/exec": "5.0.0",
5453
"@semantic-release/git": "9.0.0",
55-
"ajv": "7.0.4",
54+
"ajv": "7.1.0",
5655
"chai": "4.3.0",
5756
"chai-http": "4.3.0",
5857
"codecov": "3.8.1",
@@ -69,7 +68,7 @@
6968
"mocha": "8.2.1",
7069
"nyc": "15.1.0",
7170
"proxyquire": "2.1.3",
72-
"semantic-release": "17.3.7"
71+
"semantic-release": "17.3.8"
7372
},
7473
"lint-staged": {
7574
"*.js": "eslint"

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* OF ANY KIND, either express or implied. See the License for the specific language
1010
* governing permissions and limitations under the License.
1111
*/
12-
const { Response } = require('node-fetch');
12+
const { Response } = require('@adobe/helix-fetch');
1313
const { wrap } = require('@adobe/openwhisk-action-utils');
1414
const { logger } = require('@adobe/openwhisk-action-logger');
1515
const { wrap: helixStatus } = require('@adobe/helix-status');

src/matchers/excel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function extract(url, params, env, log = console) {
3030
log,
3131
});
3232
let item = await drive.getDriveItemFromShareLink(url);
33+
/* istanbul ignore else */
3334
if (!item.lastModifiedDateTime) {
3435
item = await drive.getDriveItem(item);
3536
}

src/matchers/run-query.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
*/
1212
/* eslint-disable camelcase */
1313

14-
// force HTTP/1 in order to avoid issues with long-lived HTTP/2 sessions
15-
// on azure/kubernetes based I/O Runtime
16-
process.env.HELIX_FETCH_FORCE_HTTP1 = true;
17-
const { fetch } = require('@adobe/helix-fetch').context({
18-
httpsProtocols:
19-
/* istanbul ignore next */
20-
process.env.HELIX_FETCH_FORCE_HTTP1 ? ['http1'] : ['http2', 'http1'],
21-
});
2214
const { utils } = require('@adobe/helix-shared');
15+
const fetchAPI = require('@adobe/helix-fetch');
16+
17+
const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1
18+
? fetchAPI.context({ alpnProtocols: [fetchAPI.ALPN_HTTP1_1] })
19+
/* istanbul ignore next */
20+
: fetchAPI;
2321

2422
async function extract(url, params, env, log = console) {
2523
const host = 'https://adobeioruntime.net';

test/excel.integration.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function main(params = {}, env = {}) {
2828
});
2929
return {
3030
statusCode: resp.status,
31-
body: JSON.parse(resp.body.toString()),
31+
body: await resp.json(),
3232
headers: [...resp.headers.keys()].reduce((result, key) => {
3333
// eslint-disable-next-line no-param-reassign
3434
result[key] = resp.headers.get(key);

test/feed.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@ const { main } = require('../src/index');
1515

1616
describe('Feed Tests', () => {
1717
it('Works for RSS Feeds', async () => {
18-
const result = await main({
18+
const response = await main({
1919
url: 'https://www.example.com/data-embed-action',
2020
}, {
2121
env: {},
2222
pathInfo: {
2323
suffix: '/https://daringfireball.net/feeds/articles',
2424
},
2525
});
26-
assert.equal(result.status, 200);
27-
const body = JSON.parse(result.body);
26+
assert.equal(response.status, 200);
27+
const body = await response.json();
2828
assert.ok(body.data.length > 1);
2929
}).timeout(10000);
3030

3131
it('Works for RSS Feeds with Limits', async () => {
32-
const result = await main({
32+
const response = await main({
3333
url: 'https://www.example.com/data-embed-action?hlx_p.limit=1',
3434
}, {
3535
env: {},
3636
pathInfo: {
3737
suffix: '/https://daringfireball.net/feeds/main',
3838
},
3939
});
40-
assert.equal(result.status, 200);
41-
const body = JSON.parse(result.body);
40+
assert.equal(response.status, 200);
41+
const body = await response.json();
4242
assert.equal(body.data.length, 1);
4343
}).timeout(10000);
4444

4545
it('Rejects invalid RSS Feeds', async () => {
46-
const result = await main({
46+
const response = await main({
4747
url: 'https://www.example.com/data-embed-action?feed=atom&foo=bar',
4848
}, {
4949
env: {},
5050
pathInfo: {
5151
suffix: '/https://example.com',
5252
},
5353
});
54-
assert.equal(result.status, 500);
54+
assert.equal(response.status, 500);
5555
}).timeout(5000);
5656
});

test/index.test.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ for (let i = 0; i < 10000; i += 1) {
2424
}
2525
}
2626

27-
describe('Integration Tests', () => {
27+
describe('Integration Tests', async () => {
2828
it('Rejects missing URLs', async () => {
29-
const result = await main({
29+
const response = await main({
3030
url: 'https://www.example.com/data-embed-action',
3131
}, {});
32-
assert.equal(result.status, 400);
32+
assert.equal(response.status, 400);
3333
});
3434

3535
it('tests index with absolute run_query url', async () => {
3636
const EXPECTED_HEADERS = {
37-
'Cache-Control': ['max-age=600'],
38-
'Content-Type': ['application/json'],
37+
'cache-control': 'max-age=600',
38+
'content-type': 'application/json',
3939
};
40-
const { body, headers, status } = await main({
40+
const response = await main({
4141
url: 'https://www.example.com/data-embed-action',
4242
}, {
4343
env: {},
@@ -46,18 +46,20 @@ describe('Integration Tests', () => {
4646
},
4747
});
4848

49-
assert.ok(Array.isArray(JSON.parse(body).data));
50-
assert.deepEqual(headers.raw(), EXPECTED_HEADERS);
49+
const { headers, status } = response;
50+
const body = await response.json();
51+
assert.ok(Array.isArray(body.data));
52+
assert.deepEqual(headers.plain(), EXPECTED_HEADERS);
5153
assert.equal(status, 200);
5254
})
5355
.timeout(60000);
5456

5557
it('tests index with relative run_query url', async () => {
5658
const EXPECTED_HEADERS = {
57-
'Cache-Control': ['max-age=600'],
58-
'Content-Type': ['application/json'],
59+
'cache-control': 'max-age=600',
60+
'content-type': 'application/json',
5961
};
60-
const { body, headers, status } = await main({
62+
const response = await main({
6163
url: 'https://www.example.com/data-embed-action?fromMins=1000&toMins=0',
6264
}, {
6365
env: {},
@@ -66,21 +68,23 @@ describe('Integration Tests', () => {
6668
},
6769
});
6870

69-
assert.ok(Array.isArray(JSON.parse(body).data));
70-
assert.deepEqual(headers.raw(), EXPECTED_HEADERS);
71+
const { headers, status } = response;
72+
const body = await response.json();
73+
assert.ok(Array.isArray(body.data));
74+
assert.deepEqual(headers.plain(), EXPECTED_HEADERS);
7175
assert.equal(status, 200);
7276
}).timeout(60000);
7377

7478
it('Rejects unknown URLs', async () => {
75-
const result = await main({
79+
const response = await main({
7680
url: 'https://www.example.com/data-embed-action?',
7781
}, {
7882
env: {},
7983
pathInfo: {
8084
suffix: '/https://example.com',
8185
},
8286
});
83-
assert.equal(result.status, 404);
87+
assert.equal(response.status, 404);
8488
});
8589
});
8690

@@ -91,13 +95,13 @@ describe('Index result Tests', () => {
9195
body: TEST_DATA,
9296
}),
9397
});
94-
const result = await customMain({
98+
const response = await customMain({
9599
url: `https://www.example.com/data-embed-action?${querystring.stringify({
96100
src: 'https://foo.com',
97101
'hlx_p.limit': 10,
98102
})}`,
99103
}, {});
100-
assert.deepEqual(JSON.parse(result.body), {
104+
assert.deepEqual(await response.json(), {
101105
data: TEST_DATA.slice(0, 10),
102106
limit: 10,
103107
offset: 0,
@@ -111,13 +115,13 @@ describe('Index result Tests', () => {
111115
body: TEST_DATA,
112116
}),
113117
});
114-
const result = await customMain({
118+
const response = await customMain({
115119
url: `https://www.example.com/data-embed-action?${querystring.stringify({
116120
src: 'https://foo.com',
117121
'hlx_p.offset': 9000,
118122
})}`,
119123
}, {});
120-
assert.deepEqual(JSON.parse(result.body), {
124+
assert.deepEqual(await response.json(), {
121125
data: TEST_DATA.slice(9000),
122126
limit: 1000,
123127
offset: 9000,
@@ -131,14 +135,14 @@ describe('Index result Tests', () => {
131135
body: TEST_DATA,
132136
}),
133137
});
134-
const result = await customMain({
138+
const response = await customMain({
135139
url: `https://www.example.com/data-embed-action?${querystring.stringify({
136140
src: 'https://foo.com',
137141
'hlx_p.limit': 50,
138142
'hlx_p.offset': 100,
139143
})}`,
140144
}, {});
141-
assert.deepEqual(JSON.parse(result.body), {
145+
assert.deepEqual(await response.json(), {
142146
data: TEST_DATA.slice(100, 150),
143147
limit: 50,
144148
offset: 100,
@@ -152,12 +156,12 @@ describe('Index result Tests', () => {
152156
body: TEST_DATA,
153157
}),
154158
});
155-
const result = await customMain({
159+
const response = await customMain({
156160
url: `https://www.example.com/data-embed-action?${querystring.stringify({
157161
src: 'https://foo.com',
158162
})}`,
159163
}, {});
160-
assert.deepEqual(JSON.parse(result.body), {
164+
assert.deepEqual(await response.json(), {
161165
data: TEST_DATA.slice(0, 4970),
162166
limit: 4970,
163167
offset: 0,

0 commit comments

Comments
 (0)