Skip to content
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
22 changes: 10 additions & 12 deletions src/services/splitHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@ const messageNoFetch = 'Global fetch API is not available.';
*/
export function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'version' | 'runtime' | 'core'>, getFetch?: () => (IFetch | undefined), getOptions?: () => object): ISplitHttpClient {

const log = settings.log;
const { log, core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
const options = getOptions && getOptions();
const fetch = getFetch && getFetch();

// if fetch is not available, log Error
if (!fetch) log.error(ERROR_CLIENT_CANNOT_GET_READY, [messageNoFetch]);

return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {

const { core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
const headers: Record<string, string> = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${authorizationKey}`,
'SplitSDKVersion': version
};

const headers: Record<string, string> = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${authorizationKey}`,
'SplitSDKVersion': version
};
if (ip) headers['SplitSDKMachineIP'] = ip;
if (hostname) headers['SplitSDKMachineName'] = hostname;

if (ip) headers['SplitSDKMachineIP'] = ip;
if (hostname) headers['SplitSDKMachineName'] = hostname;
return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {

const request = objectAssign({
headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/impressionsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function impressionsTrackerFactory(
countsCache?: IImpressionCountsCacheSync
): IImpressionsTracker {

const { log, impressionListener, runtime: { ip, hostname } } = settings;
const { log, impressionListener, runtime: { ip, hostname }, version } = settings;

return {
track(impressions: ImpressionDTO[], attributes?: SplitIO.Attributes) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function impressionsTrackerFactory(
attributes,
ip,
hostname,
sdkLanguageVersion: settings.version
sdkLanguageVersion: version
};

// Wrap in a timeout because we don't want it to be blocking.
Expand Down