URI-encode secret before appending to websocket URL
This commit is contained in:
parent
9de394eedf
commit
19dfbf7f2b
3 changed files with 9 additions and 9 deletions
|
@ -47,7 +47,7 @@ function getWsUrl(apiConfig) {
|
||||||
const { hostname, port, secret } = apiConfig;
|
const { hostname, port, secret } = apiConfig;
|
||||||
let qs = '';
|
let qs = '';
|
||||||
if (typeof secret === 'string' && secret !== '') {
|
if (typeof secret === 'string' && secret !== '') {
|
||||||
qs += '?token=' + secret;
|
qs += '?token=' + encodeURIComponent(secret);
|
||||||
}
|
}
|
||||||
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ function getWsUrl(apiConfig) {
|
||||||
const { hostname, port, secret, logLevel } = apiConfig;
|
const { hostname, port, secret, logLevel } = apiConfig;
|
||||||
let qs = '?level=' + logLevel;
|
let qs = '?level=' + logLevel;
|
||||||
if (typeof secret === 'string' && secret !== '') {
|
if (typeof secret === 'string' && secret !== '') {
|
||||||
qs += '&token=' + secret;
|
qs += '&token=' + encodeURIComponent(secret);
|
||||||
}
|
}
|
||||||
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
||||||
}
|
}
|
||||||
|
@ -78,14 +78,14 @@ function fetchLogs(apiConfig, appendLog) {
|
||||||
wsState = 1;
|
wsState = 1;
|
||||||
const url = getWsUrl(apiConfig);
|
const url = getWsUrl(apiConfig);
|
||||||
const ws = new WebSocket(url);
|
const ws = new WebSocket(url);
|
||||||
ws.addEventListener('error', function(_ev) {
|
ws.addEventListener('error', function (_ev) {
|
||||||
wsState = 3;
|
wsState = 3;
|
||||||
});
|
});
|
||||||
ws.addEventListener('close', function(_ev) {
|
ws.addEventListener('close', function (_ev) {
|
||||||
wsState = 3;
|
wsState = 3;
|
||||||
fetchLogsWithFetch(apiConfig, appendLog);
|
fetchLogsWithFetch(apiConfig, appendLog);
|
||||||
});
|
});
|
||||||
ws.addEventListener('message', function(event) {
|
ws.addEventListener('message', function (event) {
|
||||||
appendData(event.data, appendLog);
|
appendData(event.data, appendLog);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -116,13 +116,13 @@ function fetchLogsWithFetch(apiConfig, appendLog) {
|
||||||
const { url, init } = getURLAndInit(apiConfig);
|
const { url, init } = getURLAndInit(apiConfig);
|
||||||
fetch(url + endpoint + '?level=' + apiConfig.logLevel, {
|
fetch(url + endpoint + '?level=' + apiConfig.logLevel, {
|
||||||
...init,
|
...init,
|
||||||
signal
|
signal,
|
||||||
}).then(
|
}).then(
|
||||||
response => {
|
(response) => {
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
pump(reader, appendLog);
|
pump(reader, appendLog);
|
||||||
},
|
},
|
||||||
err => {
|
(err) => {
|
||||||
fetched = false;
|
fetched = false;
|
||||||
if (signal.aborted) return;
|
if (signal.aborted) return;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ function getWsUrl(apiConfig) {
|
||||||
const { hostname, port, secret } = apiConfig;
|
const { hostname, port, secret } = apiConfig;
|
||||||
let qs = '';
|
let qs = '';
|
||||||
if (typeof secret === 'string' && secret !== '') {
|
if (typeof secret === 'string' && secret !== '') {
|
||||||
qs += '?token=' + secret;
|
qs += '?token=' + encodeURIComponent(secret);
|
||||||
}
|
}
|
||||||
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
return `ws://${hostname}:${port}${endpoint}${qs}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue