Skip to content

Commit 8d5bce0

Browse files
authored
fix: correct a ws intercept issue (#98)
1 parent 3e63639 commit 8d5bce0

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A JavaScript-based SDK for delivering secure browser-based web applications over
88
Learn about Ziti at [ziti.dev](https://ziti.dev)
99

1010

11-
[![Build](https://github.com/openziti/ziti-sdk-js/workflows/Build/badge.svg?branch=master)]()
11+
[![Build](https://github.com/openziti/ziti-sdk-js/workflows/Build/badge.svg?branch=main)]()
1212
[![Issues](https://img.shields.io/github/issues-raw/openziti/ziti-sdk-js)]()
1313
[![Known Vulnerabilities](https://snyk.io/test/npm/@openziti/ziti-sdk-js/badge.svg)](https://snyk.io/test/npm/@openziti/ziti-sdk-js)
1414
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -17,6 +17,7 @@ Learn about Ziti at [ziti.dev](https://ziti.dev)
1717
[![LOC](https://img.shields.io/tokei/lines/github/openziti/ziti-sdk-js)]()
1818
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=rounded)](CONTRIBUTING.md)
1919
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
20+
[![CodeSee](https://codesee-docs.s3.amazonaws.com/badge.svg)](https://app.codesee.io/maps/public/12213800-239c-11ec-8afb-0d2533b87e31)
2021

2122

2223

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@
135135
"utf-8-validate": "^5.0.4",
136136
"uuid": "^8.3.2"
137137
}
138-
}
138+
}

src/client.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,10 +980,12 @@ zitiDocumentAppendChild = ( elem, args ) => {
980980
// Transform all occurances of the DOM Proxy hostname into a URL our sw can intercept
981981
let replace = zitiConfig.httpAgent.self.host + '/ziti-dom-proxy/' + domHost;
982982
try {
983-
let newSRC = elem[0].src.replace(re, replace);
984-
elem[0].src = newSRC;
985-
console.log('zitiDocumentAppendChild() TRANSFORMED: ', elem[0].outerHTML);
986-
transformed = true;
983+
if (!isUndefined(elem[0].src)) {
984+
let newSRC = elem[0].src.replace(re, replace);
985+
elem[0].src = newSRC;
986+
console.log('zitiDocumentAppendChild() TRANSFORMED: ', elem[0].outerHTML);
987+
transformed = true;
988+
}
987989
}
988990
catch (e) {
989991
console.error(e);

src/http/request.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,17 @@ HttpRequest.prototype.getRequestOptions = async function() {
269269
// set the Cookie header
270270
let cookieHeaderValue = '';
271271
for (const cookie in cookieObject) {
272-
if (cookieObject.hasOwnProperty(cookie)) {
273-
cookieHeaderValue += cookie + '=' + cookieObject[cookie] + '; ';
272+
if (cookie !== '') {
273+
if (cookieObject.hasOwnProperty(cookie)) {
274+
cookieHeaderValue += cookie + '=' + cookieObject[cookie] + '; ';
275+
}
274276
}
275277
}
276-
headers.set('Cookie', cookieHeaderValue);
278+
if (cookieHeaderValue !== '') {
279+
headers.set('Cookie', cookieHeaderValue);
280+
} else {
281+
headers.delete('Cookie');
282+
}
277283

278284
// HTTP-network-or-cache fetch steps 2.4-2.7
279285
let contentLengthValue = null;

src/http/ziti-websocket-wrapper.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ async function initAsClient(websocket, address, protocols, options) {
590590
opts.createConnection = zitiConnect; // We're going over Ziti
591591

592592
newUrl.protocol = "http:";
593-
opts.href = newUrl.toString().toLowerCase();
593+
opts.href = newUrl.protocol + '//' + newUrl.host.toLowerCase() + newUrl.pathname + newUrl.search;
594594
opts.origin = "http://" + (zitiConfig.httpAgent.target.host).toLowerCase();
595595
if (zitiConfig.httpAgent.target.port !== '80') {
596596
if (zitiConfig.httpAgent.target.port === '443') {
@@ -973,7 +973,14 @@ function sendAfterClose(websocket, data, cb) {
973973
* @private
974974
*/
975975
function receiverOnMessage(data) {
976-
this[kWebSocket].emit('message', data);
976+
if (typeof data === 'string') {
977+
ziti._ctx.logger.info('ZitiWebSocketWrapper.receiverOnMessage() entered, emitting STRING: %o', data);
978+
this[kWebSocket].emit('message', data);
979+
} else {
980+
let blob = new Blob(data);
981+
ziti._ctx.logger.info('ZitiWebSocketWrapper.receiverOnMessage() entered, emitting BLOB: %o', blob);
982+
this[kWebSocket].emit('message', blob);
983+
}
977984
}
978985

979986
/**

0 commit comments

Comments
 (0)