mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 00:40:01 +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.Net.Http.Headers;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Microsoft.Scripting.Utils;
|
using Microsoft.Scripting.Utils;
|
||||||
|
using MQTTnet.AspNetCore;
|
||||||
using MQTTnet.Server.Configuration;
|
using MQTTnet.Server.Configuration;
|
||||||
using MQTTnet.Server.Logging;
|
using MQTTnet.Server.Logging;
|
||||||
using MQTTnet.Server.Mqtt;
|
using MQTTnet.Server.Mqtt;
|
||||||
@@ -40,6 +41,9 @@ namespace MQTTnet.Server.Web
|
|||||||
DataSharingService dataSharingService,
|
DataSharingService dataSharingService,
|
||||||
MqttSettingsModel mqttSettings)
|
MqttSettingsModel mqttSettings)
|
||||||
{
|
{
|
||||||
|
application.UseDefaultFiles();
|
||||||
|
application.UseStaticFiles();
|
||||||
|
|
||||||
application.UseHsts();
|
application.UseHsts();
|
||||||
application.UseRouting();
|
application.UseRouting();
|
||||||
application.UseCors(x => x
|
application.UseCors(x => x
|
||||||
@@ -49,9 +53,7 @@ namespace MQTTnet.Server.Web
|
|||||||
|
|
||||||
application.UseAuthentication();
|
application.UseAuthentication();
|
||||||
application.UseAuthorization();
|
application.UseAuthorization();
|
||||||
|
|
||||||
application.UseStaticFiles();
|
|
||||||
|
|
||||||
application.UseEndpoints(endpoints =>
|
application.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
@@ -81,7 +83,6 @@ namespace MQTTnet.Server.Web
|
|||||||
{
|
{
|
||||||
services.AddCors();
|
services.AddCors();
|
||||||
|
|
||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
|
||||||
services.AddMvc()
|
services.AddMvc()
|
||||||
@@ -197,7 +198,13 @@ namespace MQTTnet.Server.Web
|
|||||||
{
|
{
|
||||||
if (context.WebSockets.IsWebSocketRequest)
|
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);
|
await mqttServerService.RunWebSocketConnectionAsync(webSocket, context).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user