Skip to content

Commit

Permalink
fix: send correct user-agent header for websocket methods (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpopp07 committed Aug 8, 2019
1 parent 5633782 commit f24cac2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
19 changes: 7 additions & 12 deletions speech-to-text/v1.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import async = require('async');
import extend = require('extend');
import isStream = require('isstream');
import { getSdkHeaders } from '../lib/common';
import RecognizeStream = require('../lib/recognize-stream');
import GeneratedSpeechToTextV1 = require('./v1-generated');

// tslint:disable-next-line:no-var-requires
const pkg = require('../package.json');

const protocols = {
https: require('https'),
http: require('http')
};

const PARAMS_ALLOWED = [
'max_alternatives',
'timestamps',
Expand Down Expand Up @@ -192,11 +185,13 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
params.token_manager = this.tokenManager;
}

// include analytics headers
const sdkHeaders = getSdkHeaders('speech_to_text', 'v1', 'recognizeUsingWebSocket');

params.headers = extend(
{
'user-agent': pkg.name + '-nodejs-' + pkg.version,
authorization: this._options.headers.Authorization
},
true,
sdkHeaders,
{ authorization: this._options.headers.Authorization },
params.headers
);

Expand Down
4 changes: 4 additions & 0 deletions test/unit/speech-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe('speech_to_text', () => {
const stream = speech_to_text.recognizeUsingWebSocket();
expect(stream.options.url).toBe(service.url);
expect(stream.options.headers.authorization).toBeTruthy();
expect(stream.options.headers['User-Agent']).toBeTruthy();
expect(stream.options.headers['X-IBMCloud-SDK-Analytics']).toBe(
'service_name=speech_to_text;service_version=v1;operation_id=recognizeUsingWebSocket;async=true'
);
expect(stream.options.token_manager).toBeUndefined();
});

Expand Down
13 changes: 7 additions & 6 deletions text-to-speech/v1.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import extend = require('extend');
import { getSdkHeaders } from '../lib/common';
import SynthesizeStream = require('../lib/synthesize-stream');
import GeneratedTextToSpeechV1 = require('./v1-generated');
// tslint:disable-next-line:no-var-requires
const pkg = require('../package.json');

class TextToSpeechV1 extends GeneratedTextToSpeechV1 {
constructor(options) {
Expand Down Expand Up @@ -87,11 +86,13 @@ class TextToSpeechV1 extends GeneratedTextToSpeechV1 {
params.token_manager = this.tokenManager;
}

// include analytics headers
const sdkHeaders = getSdkHeaders('text_to_speech', 'v1', 'synthesizeUsingWebSocket');

params.headers = extend(
{
'user-agent': pkg.name + '-nodejs-' + pkg.version,
authorization: this._options.headers.Authorization
},
true,
sdkHeaders,
{ authorization: this._options.headers.Authorization },
params.headers
);

Expand Down

0 comments on commit f24cac2

Please sign in to comment.