mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Fix web socket sub protocol negotiation.
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Microsoft.Scripting.Utils;
|
||||
using MQTTnet.AspNetCore;
|
||||
using MQTTnet.Server.Configuration;
|
||||
using MQTTnet.Server.Logging;
|
||||
using MQTTnet.Server.Mqtt;
|
||||
@@ -40,6 +41,9 @@ namespace MQTTnet.Server.Web
|
||||
DataSharingService dataSharingService,
|
||||
MqttSettingsModel mqttSettings)
|
||||
{
|
||||
application.UseDefaultFiles();
|
||||
application.UseStaticFiles();
|
||||
|
||||
application.UseHsts();
|
||||
application.UseRouting();
|
||||
application.UseCors(x => x
|
||||
@@ -49,9 +53,7 @@ namespace MQTTnet.Server.Web
|
||||
|
||||
application.UseAuthentication();
|
||||
application.UseAuthorization();
|
||||
|
||||
application.UseStaticFiles();
|
||||
|
||||
|
||||
application.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
@@ -81,7 +83,6 @@ namespace MQTTnet.Server.Web
|
||||
{
|
||||
services.AddCors();
|
||||
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
services.AddMvc()
|
||||
@@ -197,7 +198,13 @@ namespace MQTTnet.Server.Web
|
||||
{
|
||||
if (context.WebSockets.IsWebSocketRequest)
|
||||
{
|
||||
using (var webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false))
|
||||
string subProtocol = null;
|
||||
if (context.Request.Headers.TryGetValue("Sec-WebSocket-Protocol", out var requestedSubProtocolValues))
|
||||
{
|
||||
subProtocol = MqttSubProtocolSelector.SelectSubProtocol(requestedSubProtocolValues);
|
||||
}
|
||||
|
||||
using (var webSocket = await context.WebSockets.AcceptWebSocketAsync(subProtocol).ConfigureAwait(false))
|
||||
{
|
||||
await mqttServerService.RunWebSocketConnectionAsync(webSocket, context).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user