Skip to content

Commit f8466c8

Browse files
committed
fix(icp): disabling ssl verification now works for websocket connection
1 parent 624de81 commit f8466c8

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

lib/recognize-stream.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class RecognizeStream extends Duplex {
117117
* @param {string} [options.base_model_version] - The version of the specified base model that is to be used with recognition request or, for the **Create a session** method, with the new session.
118118
* Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model.
119119
* The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
120+
* @param {Boolean} [options.rejectUnauthorized] - If true, disable SSL verification for the WebSocket connection
120121
*
121122
* @constructor
122123
*/
@@ -133,8 +134,15 @@ class RecognizeStream extends Duplex {
133134
this.listening = false;
134135
this.initialized = false;
135136
this.finished = false;
137+
136138
// is using iam, another authentication step is needed
137139
this.authenticated = options.token_manager ? false : true;
140+
141+
// build the last argument for the websocket constructor (clientConfig name comes from `websocket` docs)
142+
// `tlsOptions` gets passed to Node's `http` library, which allows us to pass a rejectUnauthorized option
143+
// for disabling SSL verification (for ICP)
144+
const clientConfig = this.rejectUnauthorized ? { tlsOptions: { rejectUnauthorized: false }} : null;
145+
138146
this.on('newListener', event => {
139147
if (!options.silent) {
140148
if (
@@ -225,11 +233,7 @@ class RecognizeStream extends Duplex {
225233
null,
226234
options.headers,
227235
null,
228-
{
229-
tlsOptions: {
230-
rejectUnauthorized: false,
231-
}
232-
},
236+
clientConfig
233237
));
234238

235239
// when the input stops, let the service know that we're done

speech-to-text/v1.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
477477
params.headers
478478
);
479479

480+
// allow user to disable ssl verification when using websockets
481+
params.rejectUnauthorized = this._options.rejectUnauthorized;
482+
480483
return new RecognizeStream(params);
481484
}
482485

0 commit comments

Comments
 (0)