/
ProtocolResolver.cs
48 lines (40 loc) · 1.41 KB
/
ProtocolResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
using System;
namespace Microsoft.AspNet.SignalR.Infrastructure
{
public class ProtocolResolver
{
private const string ProtocolQueryParameter = "clientProtocol";
private readonly Version _minSupportedProtocol;
private readonly Version _maxSupportedProtocol;
public ProtocolResolver() :
this(new Version(1, 2), new Version(1, 3))
{
}
public ProtocolResolver(Version min, Version max)
{
_minSupportedProtocol = min;
_maxSupportedProtocol = max;
}
public Version Resolve(IRequest request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
Version clientProtocol;
if (Version.TryParse(request.QueryString[ProtocolQueryParameter], out clientProtocol))
{
if (clientProtocol > _maxSupportedProtocol)
{
clientProtocol = _maxSupportedProtocol;
}
else if (clientProtocol < _minSupportedProtocol)
{
clientProtocol = _minSupportedProtocol;
}
}
return clientProtocol ?? _minSupportedProtocol;
}
}
}