Skip to content

Commit

Permalink
Add client certificate support to websocket connections (#5112)
Browse files Browse the repository at this point in the history
  • Loading branch information
DMarby authored and jackkav committed Sep 9, 2022
1 parent b07305a commit 8cbf4d0
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDQaumV23vAEqn4
KAJ+zQ7nKlLWVwhqMjOS7pz3HohLf4HER6SQ6bhXj2dlsW2TEDZQcOxw9jyTs4Wu
ckpqWy//UQ4LawQ3FGpst2kFAtFY6D93odh0mjPCLzQlXpcGKs6LOzlWAXWxrV6k
HRCsPT6ytnSOZNMlDNQKB+dZJ+vFz2c5LYyPXUkVenYsYH38E/ZFIz5GVRJlLhcH
IKRK3cJoGSQfljlFFDDiwvHc5/hszKIA0zHjk4MmnSw4Dm1P7fiFsI8zZEkNACBG
O/Lf6lcWX8r+1LfrGsmRfku4GrP5LXWD/ToLgmo2CAP3TBM9ftCggKhTbJfZxMWb
Q3DAui1RAgMBAAECggEBAKKM4AW7Gzdg1yPuwJN5B0iQH++ADdYVtVfBtraeH5sS
pXkaj2VehCH2fKQ5z8ZFfLcce6xWwERKXdcC2Ls+x56P7y5ElxMGX0LPgZ8g5Xo8
GVQK7LF0my22dys2LP/oXxMEa+GCXfLnzsqcyKYtVjs4RovQY0WgTbhNFcjZc+/g
PL3DclvJHJ5n9Bb+ufxJO3K7i4sxD8gcGfgXTVSghM+VCkslw0BJcqpNyGgEjI64
FTf7Qu1E0rKRGT0EKm70RffoZpLNdpMR/9GMHE5CAMSGie27AK2X8OKCgmqCh3Kp
wKqy3hRNnk9LNfhaan2LuprKlv11bJwAFAQIJSKtzOkCgYEA6n3NI5U4h//w0SeG
eaoOqXDyWmjSj4w1MbPV4sPvs1hG0iXn+w7+dfocXGawoPyu5zB9MhGf3mRB/8dp
6gb+xvYYSoVysh4VboBMJbWBlkWH4/q5KBnwuEVZDPy5fDpK449SlVmiqfpOH7hZ
wzGV5Wdwzofxp4nVIhCT/ryFYP8CgYEA44jcXh9rOHeRySo4ZofBP0QqAdT48ffl
D+VZ2q3/DNj67dYPfo8hhnEgsgVPz02ODHh8aMYVQp4OYrXpdh3/qqnWR7BB5ch1
lVFSOjytp17TSEm//vXz+WzSyrtlInGjqGazUGMpz+9j672be4y+wdxeyNDq04lr
UQXIAsP0Ia8CgYAvhA5th29NH6/MshWt0afm7dwuNc91BxRAXhCZQtrvnJO9QbEg
TomBnozgrG5eMNXAQzMbUjby+Z3mFqJ/qas25edGMoRrU21EVvsXKRB5Qt2mdMfQ
OHFu5Z6F4zAy3B0Qv5ocaW1sxCvQgaquwv183tkdAK8XI/bsUC+tDsZ4QQKBgQDL
kYTnSODa0k9CVV3Ejaydd9TFcs+PXKQ5ho7PkWBhFDfcVeni5xetesUvwITZCaAP
FDTqYF5hDZv9QJexL8Gv5OdrmAw9Ew3wG6Ofqu4KklIhmKoH5/DxtSUacHJZUKaF
Ye0H/NBJ0vnozeivrwpz0z+SFyghPg8fnDaIEtz2zQKBgHfG8/eXi1ZOiv1nLEuZ
SvJY8IU89aTqhgVsVk0g6h1jEBhZI4mTyvJe4OyC2JjxX4YD9gxu2AXSf2w7yU94
jRZdqJpLoXtcbIy9nAdYa0AyyyPKzwcSUepO2pqE3QCOSwxlplEqrWVzD9FyHFGJ
0RyshruFkeq15L6ud/6fY8Wz
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIESDCCArCgAwIBAgIRAKkiT43PW7dM415hMVMjLlIwDQYJKoZIhvcNAQELBQAw
ezEeMBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMSgwJgYDVQQLDB9kYXZp
ZEBETWFyYnktV29yayAoRGF2aWQgTWFyYnkpMS8wLQYDVQQDDCZta2NlcnQgZGF2
aWRARE1hcmJ5LVdvcm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Z2fQ+8qkTqL8
AQ3YX4UQKcWcqwRUWpmEmr+XNfqYq8UrbO/liuPh0uQh7WkxHGlLMPe76jeK1FJP
P8T+Ivh7x7MCj2G/KlwIb7OgpjCuKeR28aSz3+WDInF4lydUwHDZveByVidBaD32
NIZeX3K8nj7tGpchbDHLiCtdSwTEXFKBPm5EcvAO92alis7mozgGrG3dK1M=
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDTqFvEgk21fa9Z
e1OhPQ5BcUDIBLSY3F+1nNv5U0HKzUKEcoU+d0TER2/iNYPs2yLU2mK1UMgQsJfB
j/2ER0kVBSwJ4uk02HqtXtv/E9/RkwYycUsHZFX6wk8HVEKqfIxSgApGBoT15//l
DYFkJwtMvwib5szzmyVswHrYC15HY67o6PkNPyMfn/erOnu4akf0CA1lIg/2haeu
EmTx3mPs677f9xUt6MFHRAAZS6HZKu6THcW6VtOUybj9D+slDwQBJ2aS5Lq79VJd
cBXxCbq2UkXK/bIHkylQ2gtK2Gq8CvbnxmrGU9pXrIFRT7xLQTaUFxXeUMbGO98k
5Wu62FP9AgMBAAECggEBAMc+PCyvMPHBP9jvNFmbPRkzwHTJoSwof1xaLeT1kACV
2qENoQqdgbl3OgZqtCa6Xn6amcLvKXY0lpbash7ccBp+hOdFmJxrkIg1vMjQ76e8
TGAdsDBkLl/gnD5c/mi41+stpv4mUvGdlJENdplN++AiELuZt6M2kDNgugM4KGbv
45cwuu0DDldCSlp9ujFvn4QipEzf4wcNqvMyaNCzGw/7FyRQncZTe9J3E1RV+Tow
UWqXSR3LhRUNpn65khtPBgkE+ffAFf6d2+wwm5Cex+VOTlMQnkgtk6IgAweBkXY4
KBmzTupm1TqfQX16zUzDaq3zO2YUhwAMwxo2Dm2rIE0CgYEA29vOXaD8PXepMwDw
2tJS/c3WKNgTeZ1B8vQxlduwfuJeMHVXF20y2kO2rhEsrPTIUX7mM8Bj59vP9rcX
2P4GTBjvsvZj/yYrFV2EyXu+LjPbPMJCi8P/J8w8f0Pwy3xME/awdi477rm43cjn
cBlZNAl0KK3npDd5L5Dfs7fAuu8CgYEA9nNvdQ2EqH1wychTeg3Mj2CsnFI/lPAm
CmUL/Dmt47NXMkG+i1DfyaKTqF7M2+cWphzsk3ppwLfU2am2Uk9DgQl7BkFoLCXY
7xD0gfIAQKrbLKo9wHvjdn3j8rbnDb/A4qCA3ea5kItWviQbUdgl3amnp9Ts2tE8
3H09kLmZz9MCgYBbXonw10p8sRIcJDP0fJwI5lYuOz48uGID+f/xa49569GBCgLb
tYIAu0tcI78RUdk+JSK+NyJN5UgUHBtJDqjHT0Wudj8wdkhJZMgeg9KRmPNv2LuX
IikT/QjXSwDzUAC9+zNyqdw2ZfCyGyAzshUkTxl7Hmq6EGPIpMiTA7aQ+QKBgQDr
2Kp4DRi/mVPfdnsUWbJCH5Tv//Hi2TK+Tdb7aENVnaG7cZkkf5+5uYCu5xIK+4n8
K7/mnoYnrITgS/4zpLEIAoeeA+fqH8oLdmFXHb1KJXebtctkseqK0YzcEFbrHG89
MbZBJPS+M+ouCiWu3DfYeev8u9Jy0Tv6EUxifIuKiwKBgQDJPmxCPM3HS3fvO+7w
DlMtR52IKjohaKmMnt5EtNUR1Xs9vZCa51SvNWA6YJ+zqoGQVCXUoy77O43cewK3
crv3Hz4wWENG/bVfJQlkpFS4t+RJzNqEzeXSYQxFVfQlnhoeEAj/cZWuOJpkhmC2
2JkrwTxrofjxbbfD/m56XUusQg==
-----END PRIVATE KEY-----
25 changes: 25 additions & 0 deletions packages/insomnia-smoke-test/fixtures/certificates/localhost.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIENzCCAp+gAwIBAgIRAPKpJUU8eOZ/zg0WbmKsy8IwDQYJKoZIhvcNAQELBQAw
ezEeMBwGA1UEChMVbWtjZXJ0IGRldmVs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3GDNv2W0Adk
hCaHIDIDAKoCZVm6HYcf/GW4EhJaujnxSWPR8os25+DePeHhrgKvlHMyyevSLcqP
U+ZN3Lk8nNIgCOuhPke7J71IJAX4lklljfeL0sQHDd/5mwLlEtWvaRNGfovnfBfL
ut5Pq0QU2WkOMwdYPJ62fuCm9GX58tXb9MfezFst0EEpf2S0Tn/7TvIXq7DOfzZu
htaGf6HrfkV159ULFuAEog+2HwvPGW3wLVQN5n6QgV/uv0W40Wm1SVpEGG4cK1r4
emap+9mwik3/bLP0xeuTG8S6X7MZde3By1xo
-----END CERTIFICATE-----
40 changes: 40 additions & 0 deletions packages/insomnia-smoke-test/fixtures/certificates/rootCA-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-----BEGIN PRIVATE KEY-----
MIIG/AIBADANBgkqhkiG9w0BAQEFAASCBuYwggbiAgEAAoIBgQCix4kz1jyTIvAh
tzLqg40XpbNwbZg0VDPXkwPtb6YfOA+k/pPuPRPrhYkVoybNqWtQLBtol77SUuvy
ytJZtKY1gRTM4Hzw+ZoReEPV1ekJr5DBqMXkVQHIlpokFQsgX/dW/vzfQ0jjcfMt
HE+FYLJKWZ3Xby+fVkjSl9V75uMHD3f5klJmXKPTMGlBKf+aCwTlBvXdn9oXAqf+
jQQi1b8xvfGdXMBYEhOoW4HbdPhwMHuzMlF5y8s6Cd9WMQoEVrKiAqT7C4p79GgL
wAT6lrbCmvw85t7NKc/2+o8JvF85AcM9XkouydhMPsWl00vfApnN6EEJYX8+P5Vm
comCC5fVygxzZOj/ElpIfx4OXy39lnJLGov4etpYtV5RDKrmvSjid6wXimYHORC7
sWkJU7PqnHxooylgzbOsqlCp7GVZLzAeuSMnwJfsmSJ7GVMNq5UkQv9KygxwFmMu
OgR087Ui340y+RuqMZzJdBow+2aCYPw+zZg+nq7ZAECZbJW/OmkCAwEAAQKCAYBb
VByUquS9oOKd6A13KmvlEqEEuVimM4AKuX+Anh3Ucj3E0tjo1/fvMrLhIvLIfP+q
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DZJGLVhs+v/KFCiXYTWnHlB+ruMP+H7cr
bQX7PLugFIQUu+FJ3uFzg5ukxeRIv8tCan4ixrNtfb/IUJ05NsTpRqihAA1hUkTv
VrabMsF5DbOQTBeW3N7ddr1zyX2MIfDqAIsbfZaFEwNRFaqFRjRSzzld7jnDkCpO
6Rp89Zmei17ffQKBwFKNBHqal7Qds4pXaoOfVu6cvdYa9DlMQ85JmVOQlF7t5svM
Z53/VYg3JUyDN6vmq6RxcSo+GCfavxdHqFo+x+v81nTHKsalRtlqdK8gLkYqeFF8
RHOFH78NNUIRQrny1S+eT9TR+W2jtMuQu5kAraUAOpp0ke40vLi5wDOqlvfkXbOt
e/H59F2gB77qwCmWfQfJzInd51LnFeeWa1jSXy+dbVtySTZ3G8594HZbpWzcbi5w
JOZoQxXn55Y+rChcYQKBwBZDTwcLMCW3WuHhNDAOOf7xx+OnvChcTDMhbMtNeGNv
47UtHZ2FQF1UpeyGmTlKwbiBPPk8fU90yR+vf9wKAQTFLV/gtFsDC8cnMr75t4Jq
GJzKfO88oNqY8Tvxr3s94wW1YTLqFqGBPSdKVy7+vcZfsR6e+x9I2Tj7r8b6wzLE
qwNBQNufwef4eoDzyE69dIaaDHHTV1q+Z1bOF4XGAcm/efK3jhNlPK98tSCme+jr
TmvRvDdQuagS/w4gM0gSrA==
-----END PRIVATE KEY-----
28 changes: 28 additions & 0 deletions packages/insomnia-smoke-test/fixtures/certificates/rootCA.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN CERTIFICATE-----
MIIExTCCAy2gAwIBAgIQb/tURt+KKadPV6mtgAlcPDANBgkqhkiG9w0BAQsFADB7
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExKDAmBgNVBAsMH2Rhdmlk
QERNYXJieS1Xb3JrIChEYXZpZCBNYXJieSkxLzAtBgNVBAMMJm1rY2VydCBkYXZp
ZEBETWFyYnktV29yayAoRGF2aWQgTWFyYnkpMB4XDTIyMDgy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HDNAQnxf1OVdRREPWD4/Di9EhYr6T5BaRVuD/pB4eYUb9shqD
6vLKVYb/vpYIHc5vEDYT4cmaFW8rXJc+gHZzs+SkTpjvUKZrz9JRrdAji+djPQlD
ZRry4t9De7nVdCZDGjbwzwuEtJxoveldDKcZ/BtRb7dVbU7SB6WqKjUzqlnCoLdE
eZBU2d6+r/ojnPCxHgzVRzABYF4vakIYg4VDVFYEVqdnBo8n5PJLX2gAHbaasOQ4
hPYthHs8RVk2O5+A/mBVeE09yCwhOAxvqi91ttS4uuN2ullmr07232Wzgc64GSJf
g1WKYRpirTEbH49z3lXRIwGaq2J1xArHsA==
-----END CERTIFICATE-----
20 changes: 19 additions & 1 deletion packages/insomnia-smoke-test/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
import { readFileSync } from 'fs';
import { createServer } from 'https';
import { join } from 'path';

import { basicAuthRouter } from './basic-auth';
import githubApi from './github-api';
Expand All @@ -11,6 +14,7 @@ import { startWebSocketServer } from './websocket';

const app = express();
const port = 4010;
const httpsPort = 4011;
const grpcPort = 50051;

app.get('/pets/:id', (req, res) => {
Expand Down Expand Up @@ -60,5 +64,19 @@ startGRPCServer(grpcPort).then(() => {
console.log(`Listening at http://localhost:${port}`);
console.log(`Listening at ws://localhost:${port}`);
});
startWebSocketServer(server);

const httpsServer = createServer({
cert: readFileSync(join(__dirname, '../fixtures/certificates/localhost.pem')),
ca: readFileSync(join(__dirname, '../fixtures/certificates/rootCA.pem')),
key: readFileSync(join(__dirname, '../fixtures/certificates/localhost-key.pem')),
// Only allow connections using valid client certificates
requestCert: true,
rejectUnauthorized: true,
}, app);
httpsServer.listen(httpsPort, () => {
console.log(`Listening at https://localhost:${httpsPort}`);
console.log(`Listening at wss://localhost:${httpsPort}`);
});

startWebSocketServer(server, httpsServer);
});
45 changes: 24 additions & 21 deletions packages/insomnia-smoke-test/server/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import { Server } from 'http';
import { WebSocketServer } from 'ws';
import { IncomingMessage, Server } from 'http';
import { WebSocket, WebSocketServer } from 'ws';

/**
* Starts an echo WebSocket server that receives messages from a client and echoes them back.
*/
export function startWebSocketServer(server: Server) {
export function startWebSocketServer(server: Server, httpsServer: Server) {
const wsServer = new WebSocketServer({ server });
const wssServer = new WebSocketServer({ server: httpsServer });

wsServer.on('connection', (ws, req) => {
console.log('WebSocket connection was opened');
console.log('Upgrade headers:', req.headers);
ws.on('message', (message, isBinary) => {
if (isBinary) {
ws.send(message);
return;
}
if (message.toString() === 'close') {
ws.close(1003, 'Invalid message type');
}
ws.send(message.toString());
});
wsServer.on('connection', handleConnection);
wssServer.on('connection', handleConnection);
}

const handleConnection = (ws: WebSocket, req: IncomingMessage) => {
console.log('WebSocket connection was opened');
console.log('Upgrade headers:', req.headers);

ws.on('close', () => {
console.log('WebSocket connection was closed');
});
ws.on('message', (message, isBinary) => {
if (isBinary) {
ws.send(message);
return;
}
if (message.toString() === 'close') {
ws.close(1003, 'Invalid message type');
}
ws.send(message.toString());
});

return wsServer;
}
ws.on('close', () => {
console.log('WebSocket connection was closed');
});
};
40 changes: 38 additions & 2 deletions packages/insomnia/src/main/network/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import electron, { ipcMain } from 'electron';
import fs from 'fs';
import { setDefaultProtocol } from 'insomnia-url';
import mkdirp from 'mkdirp';
import path from 'path';
import { KeyObject, PxfObject } from 'tls';
import { v4 as uuidV4 } from 'uuid';
import {
CloseEvent,
Expand All @@ -16,6 +18,7 @@ import { websocketRequest } from '../../models';
import * as models from '../../models';
import type { Response } from '../../models/response';
import { BaseWebSocketRequest } from '../../models/websocket-request';
import { urlMatchesCertHost } from '../../network/url-matches-cert-host';

export interface WebSocketConnection extends WebSocket {
_id: string;
Expand Down Expand Up @@ -95,7 +98,7 @@ function dispatchWebSocketEvent(target: Electron.WebContents, eventChannel: stri

async function createWebSocketConnection(
event: Electron.IpcMainInvokeEvent,
options: { requestId: string }
options: { requestId: string; workspaceId: string }
) {
const existingConnection = WebSocketConnections.get(options.requestId);

Expand Down Expand Up @@ -126,8 +129,41 @@ async function createWebSocketConnection(
const headers = request.headers.filter(({ value, disabled }) => !!value && !disabled)
.reduce(reduceArrayToLowerCaseKeyedDictionary, {});

const settings = await models.settings.getOrCreate();
const start = performance.now();
const ws = new WebSocket(request.url, { headers });

const clientCertificates = await models.clientCertificate.findByParentId(options.workspaceId);
const filteredClientCertificates = clientCertificates.filter(c => !c.disabled && urlMatchesCertHost(setDefaultProtocol(c.host, 'wss:'), request.url));
const pemCertificates: string[] = [];
const pemCertificateKeys: KeyObject[] = [];
const pfxCertificates: PxfObject[] = [];

filteredClientCertificates.forEach(clientCertificate => {
const { passphrase, cert, key, pfx } = clientCertificate;

if (cert) {
timelineFileStreams.get(options.requestId)?.write(JSON.stringify({ value: `Adding SSL PEM certificate: ${cert}`, name: 'Text', timestamp: Date.now() }) + '\n');
pemCertificates.push(fs.readFileSync(cert, 'utf-8'));
}

if (key) {
timelineFileStreams.get(options.requestId)?.write(JSON.stringify({ value: `Adding SSL KEY certificate: ${key}`, name: 'Text', timestamp: Date.now() }) + '\n');
pemCertificateKeys.push({ pem: fs.readFileSync(key, 'utf-8'), passphrase: passphrase ?? undefined });
}

if (pfx) {
timelineFileStreams.get(options.requestId)?.write(JSON.stringify({ value: `Adding SSL P12 certificate: ${pfx}`, name: 'Text', timestamp: Date.now() }) + '\n');
pfxCertificates.push({ buf: fs.readFileSync(pfx, 'utf-8'), passphrase: passphrase ?? undefined });
}
});

const ws = new WebSocket(request.url, {
headers,
cert: pemCertificates,
key: pemCertificateKeys,
pfx: pfxCertificates,
rejectUnauthorized: settings.validateSSL,
});
WebSocketConnections.set(options.requestId, ws);

ws.on('upgrade', async incoming => {
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import type { WebSocketEvent } from './main/network/websocket';

const webSocketConnection = {
create: (options: { requestId: string }) => {
create: (options: { requestId: string; workspaceId: string }) => {
return ipcRenderer.invoke('webSocketRequest.connection.create', options);
},
close: (options: { requestId: string }) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/insomnia/src/ui/components/websockets/action-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ActionButton: FC<ActionButtonProps> = ({ requestId, readyState }) => {

interface ActionBarProps {
requestId: string;
workspaceId: string;
defaultValue: string;
readyState: ReadyState;
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
Expand All @@ -75,10 +76,10 @@ const WebSocketIcon = styled.span({
paddingLeft: 'var(--padding-md)',
});

export const WebSocketActionBar: FC<ActionBarProps> = ({ requestId, defaultValue, onChange, readyState }) => {
export const WebSocketActionBar: FC<ActionBarProps> = ({ requestId, workspaceId, defaultValue, onChange, readyState }) => {
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
window.main.webSocketConnection.create({ requestId });
window.main.webSocketConnection.create({ requestId, workspaceId });
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ const WebSocketRequestForm: FC<{ requestId: string }> = ({ requestId }) => {

interface Props {
request: WebSocketRequest;
workspaceId: string;
}

// requestId is something we can read from the router params in the future.
// essentially we can lift up the states and merge request pane and response pane into a single page and divide the UI there.
// currently this is blocked by the way page layout divide the panes with dragging functionality
// TODO: @gatzjames discuss above assertion in light of request and settings drills
export const WebSocketRequestPane: FC<Props> = ({ request }) => {
export const WebSocketRequestPane: FC<Props> = ({ request, workspaceId }) => {
const readyState = useWSReadyState(request._id);
const handleOnChange = (event: ChangeEvent<HTMLInputElement>) => {
const url = event.currentTarget.value || '';
Expand All @@ -85,6 +86,7 @@ export const WebSocketRequestPane: FC<Props> = ({ request }) => {
<WebSocketActionBar
key={request._id}
requestId={request._id}
workspaceId={workspaceId}
defaultValue={request.url}
readyState={readyState}
onChange={handleOnChange}
Expand Down
Loading

0 comments on commit 8cbf4d0

Please sign in to comment.