Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpListenerContext.cs
Go to the documentation of this file.
9
10namespace System.Net;
11
12public sealed class HttpListenerContext
13{
15
17
19
20 private string _mutualAuthentication;
21
23
24 public IPrincipal? User => _user;
25
27
29 {
30 get
31 {
32 if (_response == null)
33 {
35 }
36 return _response;
37 }
38 }
39
40 internal HttpListenerSession ListenerSession { get; private set; }
41
43
45
47
49
51
52 internal ulong RequestId => Request.RequestId;
53
55 {
57 }
58
59 public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, TimeSpan keepAliveInterval)
60 {
61 return AcceptWebSocketAsync(subProtocol, 16384, keepAliveInterval);
62 }
63
64 internal unsafe HttpListenerContext(HttpListenerSession session, RequestContextBase memoryBlob)
65 {
66 if (System.Net.NetEventSource.Log.IsEnabled())
67 {
68 System.Net.NetEventSource.Info(this, $"httpListener {session.Listener} requestBlob={(IntPtr)memoryBlob.RequestBlob}", ".ctor");
69 }
70 _listener = session.Listener;
71 ListenerSession = session;
72 Request = new HttpListenerRequest(this, memoryBlob);
75 if (System.Net.NetEventSource.Log.IsEnabled())
76 {
77 System.Net.NetEventSource.Info(this, $"HttpListener: {_listener} HttpListenerRequest: {Request}", ".ctor");
78 }
79 }
80
81 internal void SetIdentity(IPrincipal principal, string mutualAuthentication)
82 {
83 _mutualAuthentication = mutualAuthentication;
84 _user = principal;
85 if (System.Net.NetEventSource.Log.IsEnabled())
86 {
87 System.Net.NetEventSource.Info(this, FormattableStringFactory.Create("mutual: {0}, Principal: {1}", (mutualAuthentication == null) ? "<null>" : mutualAuthentication, principal), "SetIdentity");
88 }
89 }
90
91 public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
92 {
93 HttpWebSocket.ValidateOptions(subProtocol, receiveBufferSize, 16, keepAliveInterval);
94 ArraySegment<byte> internalBuffer = WebSocketBuffer.CreateInternalBufferArraySegment(receiveBufferSize, 16, isServerBuffer: true);
95 return AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
96 }
97
98 [EditorBrowsable(EditorBrowsableState.Never)]
99 public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer)
100 {
101 return HttpWebSocket.AcceptWebSocketAsync(this, subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
102 }
103
104 internal void Close()
105 {
106 try
107 {
108 _response?.Close();
109 }
110 finally
111 {
112 try
113 {
114 Request.Close();
115 }
116 finally
117 {
118 IDisposable disposable = ((_user == null) ? null : (_user.Identity as IDisposable));
119 if (disposable != null && _user.Identity.AuthenticationType != "NTLM" && !_listener.UnsafeConnectionNtlmAuthentication)
120 {
121 disposable.Dispose();
122 }
123 }
124 }
125 }
126
127 internal void Abort()
128 {
130 try
131 {
132 Request.Close();
133 }
134 finally
135 {
136 (_user?.Identity as IDisposable)?.Dispose();
137 }
138 }
139
140 internal global::Interop.HttpApi.HTTP_VERB GetKnownMethod()
141 {
142 if (System.Net.NetEventSource.Log.IsEnabled())
143 {
144 System.Net.NetEventSource.Info(this, FormattableStringFactory.Create("Visited {0}()", "GetKnownMethod"), "GetKnownMethod");
145 }
146 return global::Interop.HttpApi.GetKnownVerb(Request.RequestBuffer, Request.OriginalBlobAddress);
147 }
148
149 internal static void CancelRequest(SafeHandle requestQueueHandle, ulong requestId)
150 {
151 global::Interop.HttpApi.HttpCancelHttpRequest(requestQueueHandle, requestId, IntPtr.Zero);
152 }
153
154 internal void ForceCancelRequest(SafeHandle requestQueueHandle, ulong requestId)
155 {
156 uint num = global::Interop.HttpApi.HttpCancelHttpRequest(requestQueueHandle, requestId, IntPtr.Zero);
157 if (num == 1229)
158 {
159 _response.CancelLastWrite(requestQueueHandle);
160 }
161 }
162
164 {
166 }
167}
Task< HttpListenerWebSocketContext > AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
ThreadPoolBoundHandle RequestQueueBoundHandle
Task< HttpListenerWebSocketContext > AcceptWebSocketAsync(string? subProtocol, TimeSpan keepAliveInterval)
void SetIdentity(IPrincipal principal, string mutualAuthentication)
global::Interop.HttpApi.HTTP_VERB GetKnownMethod()
unsafe HttpListenerContext(HttpListenerSession session, RequestContextBase memoryBlob)
void ForceCancelRequest(SafeHandle requestQueueHandle, ulong requestId)
Task< HttpListenerWebSocketContext > AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment< byte > internalBuffer)
Task< HttpListenerWebSocketContext > AcceptWebSocketAsync(string? subProtocol)
static void CancelRequest(SafeHandle requestQueueHandle, ulong requestId)
void CancelLastWrite(SafeHandle requestQueueHandle)
ThreadPoolBoundHandle RequestQueueBoundHandle
void SetAuthenticationHeaders(HttpListenerContext context)
ExtendedProtectionPolicy ExtendedProtectionPolicy
AuthenticationSchemes AuthenticationSchemes
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void ValidateOptions(string subProtocol, int receiveBufferSize, int sendBufferSize, TimeSpan keepAliveInterval)
static Task< HttpListenerWebSocketContext > AcceptWebSocketAsync(HttpListenerContext context, string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment< byte > internalBuffer)
static ArraySegment< byte > CreateInternalBufferArraySegment(int receiveBufferSize, int sendBufferSize, bool isServerBuffer)
static TimeSpan DefaultKeepAliveInterval
Definition WebSocket.cs:20
static FormattableString Create(string format, params object?[] arguments)
static readonly IntPtr Zero
Definition IntPtr.cs:18