-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
OwinEnvironmentExtensions.cs
107 lines (91 loc) · 3.42 KB
/
OwinEnvironmentExtensions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
namespace Microsoft.AspNet.SignalR
{
internal static class OwinEnvironmentExtensions
{
internal static CancellationToken GetShutdownToken(this IDictionary<string, object> env)
{
object value;
return env.TryGetValue(OwinConstants.HostOnAppDisposing, out value)
&& value is CancellationToken
? (CancellationToken)value
: default(CancellationToken);
}
internal static string GetAppInstanceName(this IDictionary<string, object> environment)
{
object value;
if (environment.TryGetValue(OwinConstants.HostAppNameKey, out value))
{
var stringVal = value as string;
if (!String.IsNullOrEmpty(stringVal))
{
return stringVal;
}
}
return null;
}
internal static TextWriter GetTraceOutput(this IDictionary<string, object> environment)
{
object value;
if (environment.TryGetValue(OwinConstants.HostTraceOutputKey, out value))
{
return value as TextWriter;
}
return null;
}
internal static bool SupportsWebSockets(this IDictionary<string, object> environment)
{
object value;
if (environment.TryGetValue(OwinConstants.ServerCapabilities, out value))
{
var capabilities = value as IDictionary<string, object>;
if (capabilities != null)
{
return capabilities.ContainsKey(OwinConstants.WebSocketVersion);
}
}
return false;
}
internal static bool IsDebugEnabled(this IDictionary<string, object> environment)
{
object value;
if (environment.TryGetValue(OwinConstants.HostAppModeKey, out value))
{
var stringVal = value as string;
return !String.IsNullOrWhiteSpace(stringVal) &&
OwinConstants.AppModeDevelopment.Equals(stringVal, StringComparison.OrdinalIgnoreCase);
}
return false;
}
internal static IEnumerable<Assembly> GetReferenceAssemblies(this IDictionary<string, object> environment)
{
object assembliesValue;
if (environment.TryGetValue(OwinConstants.HostReferencedAssembliesKey, out assembliesValue))
{
return (IEnumerable<Assembly>)assembliesValue;
}
return null;
}
internal static void DisableResponseBuffering(this IDictionary<string, object> environment)
{
var action = environment.Get<Action>(OwinConstants.DisableResponseBuffering);
if (action != null)
{
action();
}
}
internal static void DisableRequestCompression(this IDictionary<string, object> environment)
{
var action = environment.Get<Action>(OwinConstants.DisableRequestCompression);
if (action != null)
{
action();
}
}
}
}