Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure web-socket connection for GridAPIClient #111

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/grid-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const HTTP_PATH_VERB = {
};

export default class GridAPIClient {
constructor({ url }) {
constructor({ url, allowInsecureUrl = false }) {
this.transport = url.match(/^ws/i) ? 'ws' : 'http';
if (this.transport === 'ws') {
this.wsUrl = url;
Expand All @@ -16,6 +16,10 @@ export default class GridAPIClient {
this.httpUrl = url;
this.wsUrl = url.replace(/^http(s)?/i, 'ws$1');
}
if (!allowInsecureUrl) {
this.wsUrl = this.wsUrl.replace('ws', 'wss');
this.httpUrl = this.httpUrl.replace('http', 'https');
}
this.ws = null;
this.logger = new Logger('grid', true);
this.responseTimeout = 10000;
Expand Down
8 changes: 4 additions & 4 deletions src/syft.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export default class Syft {
// For creating verbose logging should the worker desire
this.logger = new Logger('syft.js', verbose);

this.gridClient = new GridAPIClient({ url });
// Forcing connection to be secure if verbose value is false.
this.verbose = verbose;

this.gridClient = new GridAPIClient({ url, allowInsecureUrl: verbose });

// objects registry
this.objects = {};

// For creating event listeners
this.observer = new EventObserver();

// Forcing connection to be secure if verbose value is false.
this.verbose = verbose;

this.worker_id = null;
this.peerConfig = peerConfig;
this.authToken = authToken;
Expand Down