New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/signalr

Package Overview
Dependencies
Maintainers
3
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/signalr - npm Package Compare versions

Comparing version 5.0.0-preview.2.20167.3 to 5.0.0-preview.3.20215.14

6

dist/cjs/DefaultHttpClient.js

@@ -18,3 +18,3 @@ "use strict";

var HttpClient_1 = require("./HttpClient");
var NodeHttpClient_1 = require("./NodeHttpClient");
var Utils_1 = require("./Utils");
var XhrHttpClient_1 = require("./XhrHttpClient");

@@ -27,3 +27,3 @@ /** Default implementation of {@link @microsoft/signalr.HttpClient}. */

var _this = _super.call(this) || this;
if (typeof fetch !== "undefined") {
if (typeof fetch !== "undefined" || Utils_1.Platform.isNode) {
_this.httpClient = new FetchHttpClient_1.FetchHttpClient(logger);

@@ -35,3 +35,3 @@ }

else {
_this.httpClient = new NodeHttpClient_1.NodeHttpClient(logger);
throw new Error("No usable HttpClient found.");
}

@@ -38,0 +38,0 @@ return _this;

@@ -61,2 +61,3 @@ "use strict";

var ILogger_1 = require("./ILogger");
var Utils_1 = require("./Utils");
var FetchHttpClient = /** @class */ (function (_super) {

@@ -67,2 +68,19 @@ __extends(FetchHttpClient, _super);

_this.logger = logger;
if (typeof fetch === "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
// Cookies aren't automatically handled in Node so we need to add a CookieJar to preserve cookies across requests
_this.jar = new (requireFunc("tough-cookie")).CookieJar();
_this.fetchType = requireFunc("node-fetch");
// node-fetch doesn't have a nice API for getting and setting cookies
// fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
_this.fetchType = requireFunc("fetch-cookie")(_this.fetchType, _this.jar);
// Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
_this.abortControllerType = requireFunc("abort-controller");
}
else {
_this.fetchType = fetch.bind(self);
_this.abortControllerType = AbortController;
}
return _this;

@@ -88,3 +106,3 @@ }

}
abortController = new AbortController();
abortController = new this.abortControllerType();
// Hook our abortSignal into the abort controller

@@ -109,3 +127,3 @@ if (request.abortSignal) {

_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, fetch(request.url, {
return [4 /*yield*/, this.fetchType(request.url, {
body: request.content,

@@ -151,2 +169,10 @@ cache: "no-cache",

};
FetchHttpClient.prototype.getCookieString = function (url) {
var cookies = "";
if (Utils_1.Platform.isNode && this.jar) {
// @ts-ignore: unused variable
this.jar.getCookies(url, function (e, c) { return cookies = c.join("; "); });
}
return cookies;
};
return FetchHttpClient;

@@ -153,0 +179,0 @@ }(HttpClient_1.HttpClient));

"use strict";
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -48,11 +56,2 @@ return new (P || (P = Promise))(function (resolve, reject) {

var MAX_REDIRECTS = 100;
var WebSocketModule = null;
var EventSourceModule = null;
if (Utils_1.Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
WebSocketModule = requireFunc("ws");
EventSourceModule = requireFunc("eventsource");
}
/** @private */

@@ -75,2 +74,11 @@ var HttpConnection = /** @class */ (function () {

}
var webSocketModule = null;
var eventSourceModule = null;
if (Utils_1.Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
webSocketModule = requireFunc("ws");
eventSourceModule = requireFunc("eventsource");
}
if (!Utils_1.Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {

@@ -80,4 +88,4 @@ options.WebSocket = WebSocket;

else if (Utils_1.Platform.isNode && !options.WebSocket) {
if (WebSocketModule) {
options.WebSocket = WebSocketModule;
if (webSocketModule) {
options.WebSocket = webSocketModule;
}

@@ -89,4 +97,4 @@ }

else if (Utils_1.Platform.isNode && !options.EventSource) {
if (typeof EventSourceModule !== "undefined") {
options.EventSource = EventSourceModule;
if (typeof eventSourceModule !== "undefined") {
options.EventSource = eventSourceModule;
}

@@ -113,3 +121,3 @@ }

}
this.connectionState = "Connecting " /* Connecting */;
this.connectionState = "Connecting" /* Connecting */;
this.startInternalPromise = this.startInternal(transferFormat);

@@ -308,3 +316,3 @@ return [4 /*yield*/, this.startInternalPromise];

}
if (this.connectionState === "Connecting " /* Connecting */) {
if (this.connectionState === "Connecting" /* Connecting */) {
// Ensure the connection transitions to the connected state prior to completing this.startInternalPromise.

@@ -352,3 +360,3 @@ // start() will handle the case when stop was called and startInternal exits still in the disconnecting state.

content: "",
headers: headers,
headers: __assign({}, headers, this.options.headers),
withCredentials: this.options.withCredentials,

@@ -441,3 +449,3 @@ })];

transportExceptions.push(endpoint.transport + " failed: " + ex_2);
if (this.connectionState !== "Connecting " /* Connecting */) {
if (this.connectionState !== "Connecting" /* Connecting */) {
message = "Failed to select transport before stop() was called.";

@@ -466,3 +474,3 @@ this.logger.log(ILogger_1.LogLevel.Debug, message);

}
return new WebSocketTransport_1.WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket);
return new WebSocketTransport_1.WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket, this.options.headers || {});
case ITransport_1.HttpTransportType.ServerSentEvents:

@@ -472,5 +480,5 @@ if (!this.options.EventSource) {

}
return new ServerSentEventsTransport_1.ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials);
return new ServerSentEventsTransport_1.ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials, this.options.headers || {});
case ITransport_1.HttpTransportType.LongPolling:
return new LongPollingTransport_1.LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials);
return new LongPollingTransport_1.LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials, this.options.headers || {});
default:

@@ -536,3 +544,3 @@ throw new Error("Unknown transport: " + transport + ".");

}
if (this.connectionState === "Connecting " /* Connecting */) {
if (this.connectionState === "Connecting" /* Connecting */) {
this.logger.log(ILogger_1.LogLevel.Warning, "Call to HttpConnection.stopConnection(" + error + ") was ignored because the connection is still in the connecting state.");

@@ -539,0 +547,0 @@ throw new Error("HttpConnection.stopConnection(" + error + ") was called while the connection is still in the connecting state.");

"use strict";
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -48,3 +56,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var LongPollingTransport = /** @class */ (function () {
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, withCredentials) {
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, withCredentials, headers) {
this.httpClient = httpClient;

@@ -56,2 +64,3 @@ this.accessTokenFactory = accessTokenFactory;

this.withCredentials = withCredentials;
this.headers = headers;
this.running = false;

@@ -71,5 +80,5 @@ this.onreceive = null;

return __awaiter(this, void 0, void 0, function () {
var headers, _a, name, value, pollOptions, token, pollUrl, response;
return __generator(this, function (_b) {
switch (_b.label) {
var _a, _b, name, value, headers, pollOptions, token, pollUrl, response;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -86,5 +95,4 @@ Utils_1.Arg.isRequired(url, "url");

}
headers = {};
_a = Utils_1.getUserAgentHeader(), name = _a[0], value = _a[1];
headers[name] = value;
_b = Utils_1.getUserAgentHeader(), name = _b[0], value = _b[1];
headers = __assign((_a = {}, _a[name] = value, _a), this.headers);
pollOptions = {

@@ -101,3 +109,3 @@ abortSignal: this.pollAbort.signal,

case 1:
token = _b.sent();
token = _c.sent();
this.updateHeaderToken(pollOptions, token);

@@ -108,3 +116,3 @@ pollUrl = url + "&_=" + Date.now();

case 2:
response = _b.sent();
response = _c.sent();
if (response.statusCode !== 200) {

@@ -238,3 +246,3 @@ this.logger.log(ILogger_1.LogLevel.Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + ".");

}
return [2 /*return*/, Utils_1.sendMessage(this.logger, "LongPolling", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials)];
return [2 /*return*/, Utils_1.sendMessage(this.logger, "LongPolling", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers)];
});

@@ -265,3 +273,3 @@ });

deleteOptions = {
headers: headers,
headers: __assign({}, headers, this.headers),
withCredentials: this.withCredentials,

@@ -268,0 +276,0 @@ };

"use strict";
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -45,3 +53,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var ServerSentEventsTransport = /** @class */ (function () {
function ServerSentEventsTransport(httpClient, accessTokenFactory, logger, logMessageContent, eventSourceConstructor, withCredentials) {
function ServerSentEventsTransport(httpClient, accessTokenFactory, logger, logMessageContent, eventSourceConstructor, withCredentials, headers) {
this.httpClient = httpClient;

@@ -53,2 +61,3 @@ this.accessTokenFactory = accessTokenFactory;

this.eventSourceConstructor = eventSourceConstructor;
this.headers = headers;
this.onreceive = null;

@@ -91,8 +100,7 @@ this.onclose = null;

var cookies = _this.httpClient.getCookieString(url);
var headers = {
Cookie: cookies,
};
var headers = {};
headers.Cookie = cookies;
var _a = Utils_1.getUserAgentHeader(), name_1 = _a[0], value = _a[1];
headers[name_1] = value;
eventSource = new _this.eventSourceConstructor(url, { withCredentials: _this.withCredentials, headers: headers });
eventSource = new _this.eventSourceConstructor(url, { withCredentials: _this.withCredentials, headers: __assign({}, headers, _this.headers) });
}

@@ -143,3 +151,3 @@ try {

}
return [2 /*return*/, Utils_1.sendMessage(this.logger, "SSE", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials)];
return [2 /*return*/, Utils_1.sendMessage(this.logger, "SSE", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers)];
});

@@ -146,0 +154,0 @@ });

"use strict";
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -44,3 +52,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

/** The version of the SignalR client. */
exports.VERSION = "5.0.0-preview.2.20167.3";
exports.VERSION = "5.0.0-preview.3.20215.14";
/** @private */

@@ -133,3 +141,3 @@ var Arg = /** @class */ (function () {

/** @private */
function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent, withCredentials) {
function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent, withCredentials, defaultHeaders) {
return __awaiter(this, void 0, void 0, function () {

@@ -158,3 +166,3 @@ var _a, headers, token, _b, name, value, responseType, response;

content: content,
headers: headers,
headers: __assign({}, headers, defaultHeaders),
responseType: responseType,

@@ -161,0 +169,0 @@ withCredentials: withCredentials,

"use strict";
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -45,3 +53,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var WebSocketTransport = /** @class */ (function () {
function WebSocketTransport(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor) {
function WebSocketTransport(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor, headers) {
this.logger = logger;

@@ -54,2 +62,3 @@ this.accessTokenFactory = accessTokenFactory;

this.onclose = null;
this.headers = headers;
}

@@ -87,5 +96,5 @@ WebSocketTransport.prototype.connect = function (url, transferFormat) {

}
// Only pass cookies when in non-browser environments
// Only pass headers when in non-browser environments
webSocket = new _this.webSocketConstructor(url, undefined, {
headers: headers,
headers: __assign({}, headers, _this.headers),
});

@@ -92,0 +101,0 @@ }

@@ -16,3 +16,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient } from "./HttpClient";
import { NodeHttpClient } from "./NodeHttpClient";
import { Platform } from "./Utils";
import { XhrHttpClient } from "./XhrHttpClient";

@@ -25,3 +25,3 @@ /** Default implementation of {@link @microsoft/signalr.HttpClient}. */

var _this = _super.call(this) || this;
if (typeof fetch !== "undefined") {
if (typeof fetch !== "undefined" || Platform.isNode) {
_this.httpClient = new FetchHttpClient(logger);

@@ -33,3 +33,3 @@ }

else {
_this.httpClient = new NodeHttpClient(logger);
throw new Error("No usable HttpClient found.");
}

@@ -36,0 +36,0 @@ return _this;

import { HttpClient, HttpRequest, HttpResponse } from "./HttpClient";
import { ILogger } from "./ILogger";
export declare class FetchHttpClient extends HttpClient {
private readonly abortControllerType;
private readonly fetchType;
private readonly jar?;
private readonly logger;

@@ -8,2 +11,3 @@ constructor(logger: ILogger);

send(request: HttpRequest): Promise<HttpResponse>;
getCookieString(url: string): string;
}

@@ -59,2 +59,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { LogLevel } from "./ILogger";
import { Platform } from "./Utils";
var FetchHttpClient = /** @class */ (function (_super) {

@@ -65,2 +66,19 @@ __extends(FetchHttpClient, _super);

_this.logger = logger;
if (typeof fetch === "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
// Cookies aren't automatically handled in Node so we need to add a CookieJar to preserve cookies across requests
_this.jar = new (requireFunc("tough-cookie")).CookieJar();
_this.fetchType = requireFunc("node-fetch");
// node-fetch doesn't have a nice API for getting and setting cookies
// fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
_this.fetchType = requireFunc("fetch-cookie")(_this.fetchType, _this.jar);
// Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
_this.abortControllerType = requireFunc("abort-controller");
}
else {
_this.fetchType = fetch.bind(self);
_this.abortControllerType = AbortController;
}
return _this;

@@ -86,3 +104,3 @@ }

}
abortController = new AbortController();
abortController = new this.abortControllerType();
// Hook our abortSignal into the abort controller

@@ -107,3 +125,3 @@ if (request.abortSignal) {

_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, fetch(request.url, {
return [4 /*yield*/, this.fetchType(request.url, {
body: request.content,

@@ -149,2 +167,10 @@ cache: "no-cache",

};
FetchHttpClient.prototype.getCookieString = function (url) {
var cookies = "";
if (Platform.isNode && this.jar) {
// @ts-ignore: unused variable
this.jar.getCookies(url, function (e, c) { return cookies = c.join("; "); });
}
return cookies;
};
return FetchHttpClient;

@@ -151,0 +177,0 @@ }(HttpClient));

import { AbortSignal } from "./AbortController";
import { MessageHeaders } from "./IHubProtocol";
/** Represents an HTTP request. */

@@ -11,5 +12,3 @@ export interface HttpRequest {

/** An object describing headers to apply to the request. */
headers?: {
[key: string]: string;
};
headers?: MessageHeaders;
/** The XMLHttpRequestResponseType to apply to the request. */

@@ -16,0 +15,0 @@ responseType?: XMLHttpRequestResponseType;

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -46,11 +54,2 @@ return new (P || (P = Promise))(function (resolve, reject) {

var MAX_REDIRECTS = 100;
var WebSocketModule = null;
var EventSourceModule = null;
if (Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
WebSocketModule = requireFunc("ws");
EventSourceModule = requireFunc("eventsource");
}
/** @private */

@@ -73,2 +72,11 @@ var HttpConnection = /** @class */ (function () {

}
var webSocketModule = null;
var eventSourceModule = null;
if (Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
webSocketModule = requireFunc("ws");
eventSourceModule = requireFunc("eventsource");
}
if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {

@@ -78,4 +86,4 @@ options.WebSocket = WebSocket;

else if (Platform.isNode && !options.WebSocket) {
if (WebSocketModule) {
options.WebSocket = WebSocketModule;
if (webSocketModule) {
options.WebSocket = webSocketModule;
}

@@ -87,4 +95,4 @@ }

else if (Platform.isNode && !options.EventSource) {
if (typeof EventSourceModule !== "undefined") {
options.EventSource = EventSourceModule;
if (typeof eventSourceModule !== "undefined") {
options.EventSource = eventSourceModule;
}

@@ -111,3 +119,3 @@ }

}
this.connectionState = "Connecting " /* Connecting */;
this.connectionState = "Connecting" /* Connecting */;
this.startInternalPromise = this.startInternal(transferFormat);

@@ -306,3 +314,3 @@ return [4 /*yield*/, this.startInternalPromise];

}
if (this.connectionState === "Connecting " /* Connecting */) {
if (this.connectionState === "Connecting" /* Connecting */) {
// Ensure the connection transitions to the connected state prior to completing this.startInternalPromise.

@@ -350,3 +358,3 @@ // start() will handle the case when stop was called and startInternal exits still in the disconnecting state.

content: "",
headers: headers,
headers: __assign({}, headers, this.options.headers),
withCredentials: this.options.withCredentials,

@@ -439,3 +447,3 @@ })];

transportExceptions.push(endpoint.transport + " failed: " + ex_2);
if (this.connectionState !== "Connecting " /* Connecting */) {
if (this.connectionState !== "Connecting" /* Connecting */) {
message = "Failed to select transport before stop() was called.";

@@ -464,3 +472,3 @@ this.logger.log(LogLevel.Debug, message);

}
return new WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket);
return new WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket, this.options.headers || {});
case HttpTransportType.ServerSentEvents:

@@ -470,5 +478,5 @@ if (!this.options.EventSource) {

}
return new ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials);
return new ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials, this.options.headers || {});
case HttpTransportType.LongPolling:
return new LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials);
return new LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials, this.options.headers || {});
default:

@@ -534,3 +542,3 @@ throw new Error("Unknown transport: " + transport + ".");

}
if (this.connectionState === "Connecting " /* Connecting */) {
if (this.connectionState === "Connecting" /* Connecting */) {
this.logger.log(LogLevel.Warning, "Call to HttpConnection.stopConnection(" + error + ") was ignored because the connection is still in the connecting state.");

@@ -537,0 +545,0 @@ throw new Error("HttpConnection.stopConnection(" + error + ") was called while the connection is still in the connecting state.");

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -6,2 +7,4 @@ import { HttpTransportType, ITransport } from "./ITransport";

export interface IHttpConnectionOptions {
/** {@link @microsoft/signalr.MessageHeaders} containing custom headers to be sent with every HTTP request. Note, setting headers in the browser will not work for WebSockets or the ServerSentEvents stream. */
headers?: MessageHeaders;
/** An {@link @microsoft/signalr.HttpClient} that will be used to make HTTP requests. */

@@ -8,0 +11,0 @@ httpClient?: HttpClient;

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger } from "./ILogger";

@@ -12,2 +13,3 @@ import { ITransport, TransferFormat } from "./ITransport";

private readonly pollAbort;
private readonly headers;
private url?;

@@ -20,3 +22,3 @@ private running;

readonly pollAborted: boolean;
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, withCredentials: boolean);
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, withCredentials: boolean, headers: MessageHeaders);
connect(url: string, transferFormat: TransferFormat): Promise<void>;

@@ -23,0 +25,0 @@ private getAccessToken;

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -46,3 +54,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var LongPollingTransport = /** @class */ (function () {
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, withCredentials) {
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, withCredentials, headers) {
this.httpClient = httpClient;

@@ -54,2 +62,3 @@ this.accessTokenFactory = accessTokenFactory;

this.withCredentials = withCredentials;
this.headers = headers;
this.running = false;

@@ -69,5 +78,5 @@ this.onreceive = null;

return __awaiter(this, void 0, void 0, function () {
var headers, _a, name, value, pollOptions, token, pollUrl, response;
return __generator(this, function (_b) {
switch (_b.label) {
var _a, _b, name, value, headers, pollOptions, token, pollUrl, response;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -84,5 +93,4 @@ Arg.isRequired(url, "url");

}
headers = {};
_a = getUserAgentHeader(), name = _a[0], value = _a[1];
headers[name] = value;
_b = getUserAgentHeader(), name = _b[0], value = _b[1];
headers = __assign((_a = {}, _a[name] = value, _a), this.headers);
pollOptions = {

@@ -99,3 +107,3 @@ abortSignal: this.pollAbort.signal,

case 1:
token = _b.sent();
token = _c.sent();
this.updateHeaderToken(pollOptions, token);

@@ -106,3 +114,3 @@ pollUrl = url + "&_=" + Date.now();

case 2:
response = _b.sent();
response = _c.sent();
if (response.statusCode !== 200) {

@@ -236,3 +244,3 @@ this.logger.log(LogLevel.Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + ".");

}
return [2 /*return*/, sendMessage(this.logger, "LongPolling", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials)];
return [2 /*return*/, sendMessage(this.logger, "LongPolling", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers)];
});

@@ -263,3 +271,3 @@ });

deleteOptions = {
headers: headers,
headers: __assign({}, headers, this.headers),
withCredentials: this.withCredentials,

@@ -266,0 +274,0 @@ };

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger } from "./ILogger";

@@ -15,5 +16,6 @@ import { ITransport, TransferFormat } from "./ITransport";

private url?;
private headers;
onreceive: ((data: string | ArrayBuffer) => void) | null;
onclose: ((error?: Error) => void) | null;
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, eventSourceConstructor: EventSourceConstructor, withCredentials: boolean);
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, eventSourceConstructor: EventSourceConstructor, withCredentials: boolean, headers: MessageHeaders);
connect(url: string, transferFormat: TransferFormat): Promise<void>;

@@ -20,0 +22,0 @@ send(data: any): Promise<void>;

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -43,3 +51,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var ServerSentEventsTransport = /** @class */ (function () {
function ServerSentEventsTransport(httpClient, accessTokenFactory, logger, logMessageContent, eventSourceConstructor, withCredentials) {
function ServerSentEventsTransport(httpClient, accessTokenFactory, logger, logMessageContent, eventSourceConstructor, withCredentials, headers) {
this.httpClient = httpClient;

@@ -51,2 +59,3 @@ this.accessTokenFactory = accessTokenFactory;

this.eventSourceConstructor = eventSourceConstructor;
this.headers = headers;
this.onreceive = null;

@@ -89,8 +98,7 @@ this.onclose = null;

var cookies = _this.httpClient.getCookieString(url);
var headers = {
Cookie: cookies,
};
var headers = {};
headers.Cookie = cookies;
var _a = getUserAgentHeader(), name_1 = _a[0], value = _a[1];
headers[name_1] = value;
eventSource = new _this.eventSourceConstructor(url, { withCredentials: _this.withCredentials, headers: headers });
eventSource = new _this.eventSourceConstructor(url, { withCredentials: _this.withCredentials, headers: __assign({}, headers, _this.headers) });
}

@@ -141,3 +149,3 @@ try {

}
return [2 /*return*/, sendMessage(this.logger, "SSE", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials)];
return [2 /*return*/, sendMessage(this.logger, "SSE", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers)];
});

@@ -144,0 +152,0 @@ });

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -25,3 +26,3 @@ import { IStreamSubscriber, ISubscription } from "./Stream";

/** @private */
export declare function sendMessage(logger: ILogger, transportName: string, httpClient: HttpClient, url: string, accessTokenFactory: (() => string | Promise<string>) | undefined, content: string | ArrayBuffer, logMessageContent: boolean, withCredentials: boolean): Promise<void>;
export declare function sendMessage(logger: ILogger, transportName: string, httpClient: HttpClient, url: string, accessTokenFactory: (() => string | Promise<string>) | undefined, content: string | ArrayBuffer, logMessageContent: boolean, withCredentials: boolean, defaultHeaders: MessageHeaders): Promise<void>;
/** @private */

@@ -28,0 +29,0 @@ export declare function createLogger(logger?: ILogger | LogLevel): ILogger;

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -42,3 +50,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

/** The version of the SignalR client. */
export var VERSION = "5.0.0-preview.2.20167.3";
export var VERSION = "5.0.0-preview.3.20215.14";
/** @private */

@@ -128,3 +136,3 @@ var Arg = /** @class */ (function () {

/** @private */
export function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent, withCredentials) {
export function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent, withCredentials, defaultHeaders) {
return __awaiter(this, void 0, void 0, function () {

@@ -153,3 +161,3 @@ var _a, headers, token, _b, name, value, responseType, response;

content: content,
headers: headers,
headers: __assign({}, headers, defaultHeaders),
responseType: responseType,

@@ -156,0 +164,0 @@ withCredentials: withCredentials,

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger } from "./ILogger";

@@ -13,5 +14,6 @@ import { ITransport, TransferFormat } from "./ITransport";

private webSocket?;
private headers;
onreceive: ((data: string | ArrayBuffer) => void) | null;
onclose: ((error?: Error) => void) | null;
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, webSocketConstructor: WebSocketConstructor);
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, webSocketConstructor: WebSocketConstructor, headers: MessageHeaders);
connect(url: string, transferFormat: TransferFormat): Promise<void>;

@@ -18,0 +20,0 @@ send(data: any): Promise<void>;

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -43,3 +51,3 @@ return new (P || (P = Promise))(function (resolve, reject) {

var WebSocketTransport = /** @class */ (function () {
function WebSocketTransport(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor) {
function WebSocketTransport(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor, headers) {
this.logger = logger;

@@ -52,2 +60,3 @@ this.accessTokenFactory = accessTokenFactory;

this.onclose = null;
this.headers = headers;
}

@@ -85,5 +94,5 @@ WebSocketTransport.prototype.connect = function (url, transferFormat) {

}
// Only pass cookies when in non-browser environments
// Only pass headers when in non-browser environments
webSocket = new _this.webSocketConstructor(url, undefined, {
headers: headers,
headers: __assign({}, headers, _this.headers),
});

@@ -90,0 +99,0 @@ }

{
"name": "@microsoft/signalr",
"version": "5.0.0-preview.2.20167.3",
"version": "5.0.0-preview.3.20215.14",
"description": "ASP.NET Core SignalR Client",

@@ -51,10 +51,12 @@ "main": "./dist/cjs/index.js",

"@types/node": "^10.9.4",
"@types/request": "^2.47.1",
"@types/tough-cookie": "^2.3.6",
"es6-promise": "^4.2.2"
},
"dependencies": {
"abort-controller": "^3.0.0",
"eventsource": "^1.0.7",
"request": "^2.88.0",
"fetch-cookie": "^0.7.3",
"node-fetch": "^2.6.0",
"ws": "^6.0.0"
}
}

@@ -39,3 +39,3 @@ JavaScript and TypeScript clients for SignalR for ASP.NET Core and Azure SignalR Service

```JavaScript
```javascript
let connection = new signalR.HubConnectionBuilder()

@@ -55,4 +55,3 @@ .withUrl("/chat")

```JavaScript
```javascript
importScripts('signalr.js');

@@ -75,3 +74,3 @@

```JavaScript
```javascript
const signalR = require("@microsoft/signalr");

@@ -78,0 +77,0 @@

@@ -8,3 +8,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { ILogger } from "./ILogger";
import { NodeHttpClient } from "./NodeHttpClient";
import { Platform } from "./Utils";
import { XhrHttpClient } from "./XhrHttpClient";

@@ -20,3 +20,3 @@

if (typeof fetch !== "undefined") {
if (typeof fetch !== "undefined" || Platform.isNode) {
this.httpClient = new FetchHttpClient(logger);

@@ -26,3 +26,3 @@ } else if (typeof XMLHttpRequest !== "undefined") {

} else {
this.httpClient = new NodeHttpClient(logger);
throw new Error("No usable HttpClient found.");
}

@@ -29,0 +29,0 @@ }

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// @ts-ignore: This will be removed from built files and is here to make the types available during dev work
import * as tough from "@types/tough-cookie";
import { AbortError, HttpError, TimeoutError } from "./Errors";
import { HttpClient, HttpRequest, HttpResponse } from "./HttpClient";
import { ILogger, LogLevel } from "./ILogger";
import { Platform } from "./Utils";
export class FetchHttpClient extends HttpClient {
private readonly abortControllerType: { prototype: AbortController, new(): AbortController };
private readonly fetchType: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
private readonly jar?: tough.CookieJar;
private readonly logger: ILogger;

@@ -14,2 +22,22 @@

this.logger = logger;
if (typeof fetch === "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
// Cookies aren't automatically handled in Node so we need to add a CookieJar to preserve cookies across requests
this.jar = new (requireFunc("tough-cookie")).CookieJar();
this.fetchType = requireFunc("node-fetch");
// node-fetch doesn't have a nice API for getting and setting cookies
// fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
this.fetchType = requireFunc("fetch-cookie")(this.fetchType, this.jar);
// Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
this.abortControllerType = requireFunc("abort-controller");
} else {
this.fetchType = fetch.bind(self);
this.abortControllerType = AbortController;
}
}

@@ -31,3 +59,3 @@

const abortController = new AbortController();
const abortController = new this.abortControllerType();

@@ -57,3 +85,3 @@ let error: any;

try {
response = await fetch(request.url!, {
response = await this.fetchType(request.url!, {
body: request.content!,

@@ -103,2 +131,11 @@ cache: "no-cache",

}
public getCookieString(url: string): string {
let cookies: string = "";
if (Platform.isNode && this.jar) {
// @ts-ignore: unused variable
this.jar.getCookies(url, (e, c) => cookies = c.join("; "));
}
return cookies;
}
}

@@ -105,0 +142,0 @@

@@ -5,2 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { AbortSignal } from "./AbortController";
import { MessageHeaders } from "./IHubProtocol";

@@ -19,3 +20,3 @@ /** Represents an HTTP request. */

/** An object describing headers to apply to the request. */
headers?: { [key: string]: string };
headers?: MessageHeaders;

@@ -22,0 +23,0 @@ /** The XMLHttpRequestResponseType to apply to the request. */

@@ -17,3 +17,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

const enum ConnectionState {
Connecting = "Connecting ",
Connecting = "Connecting",
Connected = "Connected",

@@ -43,12 +43,2 @@ Disconnected = "Disconnected",

let WebSocketModule: any = null;
let EventSourceModule: any = null;
if (Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
WebSocketModule = requireFunc("ws");
EventSourceModule = requireFunc("eventsource");
}
/** @private */

@@ -93,7 +83,18 @@ export class HttpConnection implements IConnection {

let webSocketModule: any = null;
let eventSourceModule: any = null;
if (Platform.isNode && typeof require !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
webSocketModule = requireFunc("ws");
eventSourceModule = requireFunc("eventsource");
}
if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
options.WebSocket = WebSocket;
} else if (Platform.isNode && !options.WebSocket) {
if (WebSocketModule) {
options.WebSocket = WebSocketModule;
if (webSocketModule) {
options.WebSocket = webSocketModule;
}

@@ -105,4 +106,4 @@ }

} else if (Platform.isNode && !options.EventSource) {
if (typeof EventSourceModule !== "undefined") {
options.EventSource = EventSourceModule;
if (typeof eventSourceModule !== "undefined") {
options.EventSource = eventSourceModule;
}

@@ -321,3 +322,3 @@ }

content: "",
headers,
headers: { ...headers, ...this.options.headers },
withCredentials: this.options.withCredentials,

@@ -410,3 +411,3 @@ });

}
return new WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket);
return new WebSocketTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket, this.options.headers || {});
case HttpTransportType.ServerSentEvents:

@@ -416,5 +417,5 @@ if (!this.options.EventSource) {

}
return new ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials!);
return new ServerSentEventsTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource, this.options.withCredentials!, this.options.headers || {});
case HttpTransportType.LongPolling:
return new LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials!);
return new LongPollingTransport(this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.withCredentials!, this.options.headers || {});
default:

@@ -421,0 +422,0 @@ throw new Error(`Unknown transport: ${transport}.`);

@@ -5,2 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -12,2 +13,5 @@ import { HttpTransportType, ITransport } from "./ITransport";

export interface IHttpConnectionOptions {
/** {@link @microsoft/signalr.MessageHeaders} containing custom headers to be sent with every HTTP request. Note, setting headers in the browser will not work for WebSockets or the ServerSentEvents stream. */
headers?: MessageHeaders;
/** An {@link @microsoft/signalr.HttpClient} that will be used to make HTTP requests. */

@@ -14,0 +18,0 @@ httpClient?: HttpClient;

@@ -7,2 +7,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient, HttpRequest } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -21,2 +22,3 @@ import { ITransport, TransferFormat } from "./ITransport";

private readonly pollAbort: AbortController;
private readonly headers: MessageHeaders;

@@ -36,3 +38,3 @@ private url?: string;

constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, withCredentials: boolean) {
constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger, logMessageContent: boolean, withCredentials: boolean, headers: MessageHeaders) {
this.httpClient = httpClient;

@@ -44,2 +46,3 @@ this.accessTokenFactory = accessTokenFactory;

this.withCredentials = withCredentials;
this.headers = headers;

@@ -67,5 +70,4 @@ this.running = false;

const headers = {};
const [name, value] = getUserAgentHeader();
headers[name] = value;
const headers = { [name]: value, ...this.headers };

@@ -193,3 +195,3 @@ const pollOptions: HttpRequest = {

}
return sendMessage(this.logger, "LongPolling", this.httpClient, this.url!, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials);
return sendMessage(this.logger, "LongPolling", this.httpClient, this.url!, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers);
}

@@ -215,3 +217,3 @@

const deleteOptions: HttpRequest = {
headers,
headers: { ...headers, ...this.headers },
withCredentials: this.withCredentials,

@@ -218,0 +220,0 @@ };

@@ -5,2 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -21,2 +22,3 @@ import { ITransport, TransferFormat } from "./ITransport";

private url?: string;
private headers: MessageHeaders;

@@ -27,3 +29,3 @@ public onreceive: ((data: string | ArrayBuffer) => void) | null;

constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger,
logMessageContent: boolean, eventSourceConstructor: EventSourceConstructor, withCredentials: boolean) {
logMessageContent: boolean, eventSourceConstructor: EventSourceConstructor, withCredentials: boolean, headers: MessageHeaders) {
this.httpClient = httpClient;

@@ -35,2 +37,3 @@ this.accessTokenFactory = accessTokenFactory;

this.eventSourceConstructor = eventSourceConstructor;
this.headers = headers;

@@ -71,9 +74,8 @@ this.onreceive = null;

const cookies = this.httpClient.getCookieString(url);
const headers = {
Cookie: cookies,
};
const headers: MessageHeaders = {};
headers.Cookie = cookies;
const [name, value] = getUserAgentHeader();
headers[name] = value;
eventSource = new this.eventSourceConstructor(url, { withCredentials: this.withCredentials, headers } as EventSourceInit);
eventSource = new this.eventSourceConstructor(url, { withCredentials: this.withCredentials, headers: { ...headers, ...this.headers} } as EventSourceInit);
}

@@ -120,3 +122,3 @@

}
return sendMessage(this.logger, "SSE", this.httpClient, this.url!, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials);
return sendMessage(this.logger, "SSE", this.httpClient, this.url!, this.accessTokenFactory, data, this.logMessageContent, this.withCredentials, this.headers);
}

@@ -123,0 +125,0 @@

@@ -5,2 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -89,3 +90,3 @@ import { NullLogger } from "./Loggers";

export async function sendMessage(logger: ILogger, transportName: string, httpClient: HttpClient, url: string, accessTokenFactory: (() => string | Promise<string>) | undefined,
content: string | ArrayBuffer, logMessageContent: boolean, withCredentials: boolean): Promise<void> {
content: string | ArrayBuffer, logMessageContent: boolean, withCredentials: boolean, defaultHeaders: MessageHeaders): Promise<void> {
let headers = {};

@@ -109,3 +110,3 @@ if (accessTokenFactory) {

content,
headers,
headers: { ...headers, ...defaultHeaders},
responseType,

@@ -112,0 +113,0 @@ withCredentials,

@@ -5,2 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved.

import { HttpClient } from "./HttpClient";
import { MessageHeaders } from "./IHubProtocol";
import { ILogger, LogLevel } from "./ILogger";

@@ -19,2 +20,3 @@ import { ITransport, TransferFormat } from "./ITransport";

private webSocket?: WebSocket;
private headers: MessageHeaders;

@@ -25,3 +27,3 @@ public onreceive: ((data: string | ArrayBuffer) => void) | null;

constructor(httpClient: HttpClient, accessTokenFactory: (() => string | Promise<string>) | undefined, logger: ILogger,
logMessageContent: boolean, webSocketConstructor: WebSocketConstructor) {
logMessageContent: boolean, webSocketConstructor: WebSocketConstructor, headers: MessageHeaders) {
this.logger = logger;

@@ -35,2 +37,3 @@ this.accessTokenFactory = accessTokenFactory;

this.onclose = null;
this.headers = headers;
}

@@ -66,5 +69,5 @@

// Only pass cookies when in non-browser environments
// Only pass headers when in non-browser environments
webSocket = new this.webSocketConstructor(url, undefined, {
headers,
headers: { ...headers, ...this.headers },
});

@@ -71,0 +74,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc