Skip to content

Commit f83f5ef

Browse files
committed
Disable SSE in browser
1 parent 4a56599 commit f83f5ef

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.Log.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ private static class Log
6666
private static readonly Action<ILogger, HttpTransportType, Exception> _transportStarted =
6767
LoggerMessage.Define<HttpTransportType>(LogLevel.Debug, new EventId(18, "TransportStarted"), "Transport '{Transport}' started.");
6868

69+
private static readonly Action<ILogger, Exception> _serverSentEventsNotSupportedByBrowser =
70+
LoggerMessage.Define(LogLevel.Debug, new EventId(19, "ServerSentEventsNotSupportedByBrowser"), "Skipping ServerSentEvents because they are not supported by the browser.");
71+
6972
public static void Starting(ILogger logger)
7073
{
7174
_starting(logger, null);

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public partial class HttpConnection : ConnectionContext, IConnectionInherentKeep
3737
private bool _started;
3838
private bool _disposed;
3939
private bool _hasInherentKeepAlive;
40+
private bool _isRunningInBrowser;
4041

4142
private readonly HttpClient _httpClient;
4243
private readonly HttpConnectionOptions _httpConnectionOptions;
@@ -154,6 +155,8 @@ public HttpConnection(HttpConnectionOptions httpConnectionOptions, ILoggerFactor
154155
_logScope = new ConnectionLogScope();
155156

156157
Features.Set<IConnectionInherentKeepAliveFeature>(this);
158+
159+
_isRunningInBrowser = Utils.IsRunningInBrowser();
157160
}
158161

159162
// Used by unit tests
@@ -365,6 +368,13 @@ private async Task SelectAndStartTransport(TransferFormat transferFormat, Cancel
365368
continue;
366369
}
367370

371+
if (transportType == HttpTransportType.ServerSentEvents && _isRunningInBrowser)
372+
{
373+
Log.ServerSentEventsNotSupportedByBrowser(_logger);
374+
transportExceptions.Add(new TransportFailedException("ServerSentEvents", "The transport is not supported in the browser."));
375+
continue;
376+
}
377+
368378
try
369379
{
370380
if ((transportType & _httpConnectionOptions.Transports) == 0)

0 commit comments

Comments
 (0)