mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
* Add Directory.Build.props. * Adjust Analysis related properties and add conditional enablement for ContinuousIntegrationBuild. * Adopt new changes in master --------- Co-authored-by: christian <6939810+chkr1011@users.noreply.github.com>
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace MQTTnet.AspNetCore;
|
|
|
|
public static class MqttSubProtocolSelector
|
|
{
|
|
public static string SelectSubProtocol(HttpRequest request)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(request);
|
|
|
|
string subProtocol = null;
|
|
if (request.Headers.TryGetValue("Sec-WebSocket-Protocol", out var requestedSubProtocolValues))
|
|
{
|
|
subProtocol = SelectSubProtocol(requestedSubProtocolValues);
|
|
}
|
|
|
|
return subProtocol;
|
|
}
|
|
|
|
public static string SelectSubProtocol(IList<string> requestedSubProtocolValues)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(requestedSubProtocolValues);
|
|
|
|
// Order the protocols to also match "mqtt", "mqttv-3.1", "mqttv-3.11" etc.
|
|
return requestedSubProtocolValues.OrderByDescending(p => p.Length).FirstOrDefault(p => p.ToLowerInvariant().StartsWith("mqtt", StringComparison.InvariantCulture));
|
|
}
|
|
} |