diff --git a/src/core/request.js b/src/core/request.js index a8b7f56..ef03dff 100644 --- a/src/core/request.js +++ b/src/core/request.js @@ -275,7 +275,9 @@ const request = async (ctx, uri, options) => { return await h2.request(ctx, url, socket ? { ...opts, socket } : opts); } catch (err) { const { code, message } = err; - if (code === 'ERR_HTTP2_ERROR' && message === 'Protocol error') { + /* c8 ignore next 2 */ + if ((code === 'ERR_HTTP2_ERROR' && message === 'Protocol error') + || code === 'ERR_HTTP2_STREAM_CANCEL') { // server potentially downgraded from h2 to h1: clear alpn cache entry ctx.alpnCache.delete(`${url.protocol}//${url.host}`); } diff --git a/test/fetch/index.http1.test.js b/test/fetch/index.http1.test.js index d3136bf..a21b4b6 100644 --- a/test/fetch/index.http1.test.js +++ b/test/fetch/index.http1.test.js @@ -79,6 +79,18 @@ testParams.forEach((params) => { } }); + it(`h1() defaults to 'no keep-alive' (${name})`, async () => { + const { fetch, reset } = h1({ rejectUnauthorized: false }); + try { + const resp = await fetch(`${server.origin}/status/200`); + assert.strictEqual(resp.status, 200); + assert.strictEqual(resp.httpVersion, '1.1'); + assert.strictEqual(resp.headers.get('connection'), 'close'); + } finally { + await reset(); + } + }); + it(`supports h1NoCache() (${name})`, async () => { const { fetch, cacheStats, reset } = h1NoCache({ rejectUnauthorized: false }); try { @@ -99,20 +111,6 @@ testParams.forEach((params) => { } }); - it(`defaults to 'no keep-alive' (${name})`, async () => { - const { fetch, reset } = context( - { alpnProtocols: [ALPN_HTTP1_1], rejectUnauthorized: false }, - ); - try { - const resp = await fetch(`${server.origin}/status/200`); - assert.strictEqual(resp.status, 200); - assert.strictEqual(resp.httpVersion, '1.1'); - assert.strictEqual(resp.headers.get('connection'), 'close'); - } finally { - await reset(); - } - }); - it(`supports h1.keepAlive context option (${name})`, async () => { const { fetch, reset } = context( { alpnProtocols: [ALPN_HTTP1_1], h1: { keepAlive: true }, rejectUnauthorized: false }, diff --git a/test/fetch/resiliance.test.js b/test/fetch/resiliance.test.js index 8c213e5..a78616c 100644 --- a/test/fetch/resiliance.test.js +++ b/test/fetch/resiliance.test.js @@ -63,8 +63,8 @@ describe('Fetch Resiliance Tests', () => { process.kill(server.pid); // start h1 server server = await Server.launch(1, true, HELLO_MSG, server.port); - // expect FetchError: Protocol error - await assert.rejects(ctx.fetch(`${server.origin}/hello`), { name: 'FetchError', message: 'Protocol error' }); + // expect FetchError: Protocol error (message depends on node version) + await assert.rejects(ctx.fetch(`${server.origin}/hello`), { name: 'FetchError' }); // the fetch context should have recovered by now, next request should succeed resp = await ctx.fetch(`${server.origin}/hello`); assert.strictEqual(resp.status, 200);