Add /delay endpoint to WS express server (#5326)

This commit is contained in:
Filipe Freire 2022-10-26 09:38:10 +01:00 committed by GitHub
parent ae2d91c2de
commit c501ae9963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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==') {