From c501ae99636c4c9f91f11c4ed7881e79687049d6 Mon Sep 17 00:00:00 2001 From: Filipe Freire Date: Wed, 26 Oct 2022 09:38:10 +0100 Subject: [PATCH] Add /delay endpoint to WS express server (#5326) --- .../fixtures/websockets.yaml | 20 +++++++++++++++++++ .../insomnia-smoke-test/server/websocket.ts | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/packages/insomnia-smoke-test/fixtures/websockets.yaml b/packages/insomnia-smoke-test/fixtures/websockets.yaml index d6f8b8f33..ac7bbce6c 100644 --- a/packages/insomnia-smoke-test/fixtures/websockets.yaml +++ b/packages/insomnia-smoke-test/fixtures/websockets.yaml @@ -59,6 +59,26 @@ resources: headers: [] authentication: {} _type: websocket_request + - _id: ws-req_49815a73d8bf4024baebf82037b5730d + parentId: wrk_db59cf2b74764e6a80c0dcbcf3d67130 + modified: 1666696265531 + created: 1666695713692 + name: delay + url: ws://localhost:4010/delay + metaSortKey: -1661942202573 + headers: + - id: pair_d5c62785928d4cc3a09b297bfbb847f7 + name: duration + value: "5" + description: "" + authentication: {} + parameters: [] + settingEncodeUrl: true + settingStoreCookies: true + settingSendCookies: true + settingFollowRedirects: global + description: "" + _type: websocket_request - _id: env_78d7375877d288dfb527a256e6d7e92dce4ff968 parentId: wrk_db59cf2b74764e6a80c0dcbcf3d67130 modified: 1661942194375 diff --git a/packages/insomnia-smoke-test/server/websocket.ts b/packages/insomnia-smoke-test/server/websocket.ts index f8f4801cd..3c912aacc 100644 --- a/packages/insomnia-smoke-test/server/websocket.ts +++ b/packages/insomnia-smoke-test/server/websocket.ts @@ -68,6 +68,13 @@ const upgrade = (wss: WebSocketServer, request: IncomingMessage, socket: Socket, } return redirectOnSuccess(socket); } + if (request.url === '/delay') { + const delaySec = Number.parseInt(request.headers.duration as string || '5'); + setTimeout(function() { + redirectOnSuccess(socket); + }, delaySec * 1000); + return ; + } if (request.url === '/basic-auth') { // login with user:password if (request.headers.authorization !== 'Basic dXNlcjpwYXNzd29yZA==') {