fix #106 by removing ReplaceFeature

This commit is contained in:
Andrew Stanton-Nurse 2016-11-02 15:46:22 -07:00 committed by Andrew Stanton-Nurse
parent b3f755dff3
commit f58a373704
3 changed files with 8 additions and 14 deletions

View File

@ -40,12 +40,9 @@ namespace Microsoft.AspNetCore.WebSockets
{
// Detect if an opaque upgrade is available. If so, add a websocket upgrade.
var upgradeFeature = context.Features.Get<IHttpUpgradeFeature>();
if (upgradeFeature != null)
if (upgradeFeature != null && context.Features.Get<IHttpWebSocketFeature>() == null)
{
if (_options.ReplaceFeature || context.Features.Get<IHttpWebSocketFeature>() == null)
{
context.Features.Set<IHttpWebSocketFeature>(new UpgradeHandshake(context, upgradeFeature, _options));
}
context.Features.Set<IHttpWebSocketFeature>(new UpgradeHandshake(context, upgradeFeature, _options));
}
return _next(context);

View File

@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Builder
{
KeepAliveInterval = TimeSpan.FromMinutes(2);
ReceiveBufferSize = 4 * 1024;
ReplaceFeature = false;
}
/// <summary>
@ -28,11 +27,5 @@ namespace Microsoft.AspNetCore.Builder
/// The default is 4kb.
/// </summary>
public int ReceiveBufferSize { get; set; }
/// <summary>
/// Gets or sets if the middleware should replace the WebSocket implementation provided by
/// a component earlier in the stack. This is false by default.
/// </summary>
public bool ReplaceFeature { get; set; }
}
}

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Logging;
namespace AutobahnTestApp
@ -16,11 +17,14 @@ namespace AutobahnTestApp
{
if (!env.IsEnvironment("NativeSockets"))
{
app.UseWebSockets(new WebSocketOptions
// Register a middleware that disables the server-provided WebSockets feature
app.Use((context, next) =>
{
ReplaceFeature = true
context.Features.Set<IHttpWebSocketFeature>(null);
return next();
});
}
app.UseWebSockets();
app.Use(async (context, next) =>
{