From e9d67442afaa09ed47ffac6cc5eb796106f77d4e Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Tue, 8 Jun 2021 19:29:30 +0200 Subject: [PATCH] Propagate request cancelation though basePath proxy (#101561) (#101618) * bump `@hapi/h2o2` to `9.1.0` * add unit test --- package.json | 2 +- .../src/base_path_proxy_server.test.ts | 39 +++++++++++++++++++ yarn.lock | 8 ++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 83550df3d786..42576299ff7f 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ "@hapi/boom": "^9.1.1", "@hapi/cookie": "^11.0.2", "@hapi/good-squeeze": "6.0.0", - "@hapi/h2o2": "^9.0.2", + "@hapi/h2o2": "^9.1.0", "@hapi/hapi": "^20.0.3", "@hapi/hoek": "^9.1.1", "@hapi/inert": "^6.0.3", diff --git a/packages/kbn-cli-dev-mode/src/base_path_proxy_server.test.ts b/packages/kbn-cli-dev-mode/src/base_path_proxy_server.test.ts index a0afbe3a9b8c..34c6be02847a 100644 --- a/packages/kbn-cli-dev-mode/src/base_path_proxy_server.test.ts +++ b/packages/kbn-cli-dev-mode/src/base_path_proxy_server.test.ts @@ -185,6 +185,45 @@ describe('BasePathProxyServer', () => { }); }); + test('forwards request cancellation', async () => { + let propagated = false; + + let notifyRequestReceived: () => void; + const requestReceived = new Promise((resolve) => { + notifyRequestReceived = resolve; + }); + + let notifyRequestAborted: () => void; + const requestAborted = new Promise((resolve) => { + notifyRequestAborted = resolve; + }); + + server.route({ + method: 'GET', + path: `${basePath}/foo/{test}`, + handler: async (request, h) => { + notifyRequestReceived(); + + request.raw.req.once('aborted', () => { + notifyRequestAborted(); + propagated = true; + }); + return await new Promise((resolve) => undefined); + }, + }); + await server.start(); + + const request = proxySupertest.get(`${basePath}/foo/some-string`).end(); + + await requestReceived; + + request.abort(); + + await requestAborted; + + expect(propagated).toEqual(true); + }); + test('handles putting', async () => { server.route({ method: 'PUT', diff --git a/yarn.lock b/yarn.lock index 3d1f7f93668f..29dfc7baa855 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1871,10 +1871,10 @@ "@hapi/hoek" "9.x.x" fast-safe-stringify "2.x.x" -"@hapi/h2o2@^9.0.2": - version "9.0.2" - resolved "https://registry.yarnpkg.com/@hapi/h2o2/-/h2o2-9.0.2.tgz#e9f1dfe789257c80d6ee37ec9fe358f8c69f855a" - integrity sha512-V7RsmVyl7uyWeuEko4uaSZbFpBHKcSFSui6PXNRaRLJHFX+iPbqWmeH6m1pW/WJ8DuaCVJFKhluDCDI9l4+1cw== +"@hapi/h2o2@^9.1.0": + version "9.1.0" + resolved "https://registry.yarnpkg.com/@hapi/h2o2/-/h2o2-9.1.0.tgz#b223f4978b6f2b0d7d9db10a84a567606c4c3551" + integrity sha512-B7E58bMhxmpiDI22clxTexoAaVShNBk1Ez6S8SQjQZu5FxxD6Tqa44sXeZQBtWrdJF7ZRbsY60/C8AHLRxagNA== dependencies: "@hapi/boom" "9.x.x" "@hapi/hoek" "9.x.x"