Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpListenerRequest.cs
Go to the documentation of this file.
4using System.IO;
12using System.Text;
14
15namespace System.Net;
16
17public sealed class HttpListenerRequest
18{
19 private static class Helpers
20 {
21 private sealed class UrlDecoder
22 {
23 private readonly int _bufferSize;
24
25 private int _numChars;
26
27 private readonly char[] _charBuffer;
28
29 private int _numBytes;
30
31 private byte[] _byteBuffer;
32
33 private readonly Encoding _encoding;
34
35 private void FlushBytes()
36 {
37 if (_numBytes > 0)
38 {
40 _numBytes = 0;
41 }
42 }
43
44 internal UrlDecoder(int bufferSize, Encoding encoding)
45 {
47 _encoding = encoding;
48 _charBuffer = new char[bufferSize];
49 }
50
51 internal void AddChar(char ch)
52 {
53 if (_numBytes > 0)
54 {
55 FlushBytes();
56 }
58 }
59
60 internal void AddByte(byte b)
61 {
62 if (_byteBuffer == null)
63 {
64 _byteBuffer = new byte[_bufferSize];
65 }
67 }
68
69 internal string GetString()
70 {
71 if (_numBytes > 0)
72 {
73 FlushBytes();
74 }
75 if (_numChars > 0)
76 {
77 return new string(_charBuffer, 0, _numChars);
78 }
79 return string.Empty;
80 }
81 }
82
83 internal static string GetCharSetValueFromHeader(string headerValue)
84 {
85 if (headerValue == null)
86 {
87 return null;
88 }
89 int length = headerValue.Length;
90 int length2 = "charset".Length;
91 int i;
92 for (i = 1; i < length; i += length2)
93 {
94 i = CultureInfo.InvariantCulture.CompareInfo.IndexOf(headerValue, "charset", i, CompareOptions.IgnoreCase);
96 {
97 break;
98 }
99 char c = headerValue[i - 1];
100 char c2 = headerValue[i + length2];
101 if ((c == ';' || c == ',' || char.IsWhiteSpace(c)) && (c2 == '=' || char.IsWhiteSpace(c2)))
102 {
103 break;
104 }
105 }
106 if (i < 0 || i >= length)
107 {
108 return null;
109 }
110 for (i += length2; i < length && char.IsWhiteSpace(headerValue[i]); i++)
111 {
112 }
113 if (i >= length || headerValue[i] != '=')
114 {
115 return null;
116 }
117 for (i++; i < length && char.IsWhiteSpace(headerValue[i]); i++)
118 {
119 }
120 if (i >= length)
121 {
122 return null;
123 }
124 string text = null;
125 int num;
126 if (i < length && headerValue[i] == '"')
127 {
128 if (i == length - 1)
129 {
130 return null;
131 }
132 num = headerValue.IndexOf('"', i + 1);
133 if (num < 0 || num == i + 1)
134 {
135 return null;
136 }
137 return headerValue.AsSpan(i + 1, num - i - 1).Trim().ToString();
138 }
139 for (num = i; num < length && headerValue[num] != ';'; num++)
140 {
141 }
142 if (num == i)
143 {
144 return null;
145 }
146 return headerValue.AsSpan(i, num - i).Trim().ToString();
147 }
148
149 internal static string[] ParseMultivalueHeader(string s)
150 {
151 if (s == null)
152 {
153 return null;
154 }
155 int length = s.Length;
157 int num = 0;
158 while (num < length)
159 {
160 int num2 = s.IndexOf(',', num);
161 if (num2 < 0)
162 {
163 num2 = length;
164 }
165 list.Add(s.Substring(num, num2 - num));
166 num = num2 + 1;
167 if (num < length && s[num] == ' ')
168 {
169 num++;
170 }
171 }
172 int count = list.Count;
173 string[] array;
174 if (count == 0)
175 {
176 array = new string[1] { string.Empty };
177 }
178 else
179 {
180 array = new string[count];
181 list.CopyTo(0, array, 0, count);
182 }
183 return array;
184 }
185
186 private static string UrlDecodeStringFromStringInternal(string s, Encoding e)
187 {
188 int length = s.Length;
190 for (int i = 0; i < length; i++)
191 {
192 char c = s[i];
193 switch (c)
194 {
195 case '+':
196 c = ' ';
197 break;
198 case '%':
199 if (i >= length - 2)
200 {
201 break;
202 }
203 if (s[i + 1] == 'u' && i < length - 5)
204 {
205 int num = System.HexConverter.FromChar(s[i + 2]);
206 int num2 = System.HexConverter.FromChar(s[i + 3]);
207 int num3 = System.HexConverter.FromChar(s[i + 4]);
208 int num4 = System.HexConverter.FromChar(s[i + 5]);
209 if ((num | num2 | num3 | num4) != 255)
210 {
211 c = (char)((num << 12) | (num2 << 8) | (num3 << 4) | num4);
212 i += 5;
213 urlDecoder.AddChar(c);
214 continue;
215 }
216 }
217 else
218 {
219 int num5 = System.HexConverter.FromChar(s[i + 1]);
220 int num6 = System.HexConverter.FromChar(s[i + 2]);
221 if ((num5 | num6) != 255)
222 {
223 byte b = (byte)((num5 << 4) | num6);
224 i += 2;
225 urlDecoder.AddByte(b);
226 continue;
227 }
228 }
229 break;
230 }
231 if ((c & 0xFF80) == 0)
232 {
233 urlDecoder.AddByte((byte)c);
234 }
235 else
236 {
237 urlDecoder.AddChar(c);
238 }
239 }
240 return urlDecoder.GetString();
241 }
242
243 internal static void FillFromString(NameValueCollection nvc, string s, bool urlencoded, Encoding encoding)
244 {
245 int length = s.Length;
246 for (int i = ((length > 0 && s[0] == '?') ? 1 : 0); i < length; i++)
247 {
248 int num = i;
249 int num2 = -1;
250 for (; i < length; i++)
251 {
252 switch (s[i])
253 {
254 case '=':
255 if (num2 < 0)
256 {
257 num2 = i;
258 }
259 continue;
260 default:
261 continue;
262 case '&':
263 break;
264 }
265 break;
266 }
267 string text = null;
268 string text2 = null;
269 if (num2 >= 0)
270 {
271 text = s.Substring(num, num2 - num);
272 text2 = s.Substring(num2 + 1, i - num2 - 1);
273 }
274 else
275 {
276 text2 = s.Substring(num, i - num);
277 }
278 if (urlencoded)
279 {
281 }
282 else
283 {
284 nvc.Add(text, text2);
285 }
286 if (i == length - 1 && s[i] == '&')
287 {
288 nvc.Add(null, "");
289 }
290 }
291 }
292 }
293
294 private enum SslStatus : byte
295 {
296 Insecure,
299 }
300
302
303 private bool? _keepAlive;
304
305 private string _rawUrl;
306
308
310
311 private readonly ulong _requestId;
312
313 internal ulong _connectionId;
314
315 private readonly SslStatus _sslStatus;
316
317 private readonly string _cookedUrlHost;
318
319 private readonly string _cookedUrlPath;
320
321 private readonly string _cookedUrlQuery;
322
323 private long _contentLength;
324
326
327 private string _httpMethod;
328
330
332
334
336
338
340
342
343 private bool _isDisposed;
344
345 private string _serviceName;
346
347 public string[]? AcceptTypes => Helpers.ParseMultivalueHeader(Headers["Accept"]);
348
349 public string[]? UserLanguages => Helpers.ParseMultivalueHeader(Headers["Accept-Language"]);
350
352 {
353 get
354 {
355 if (_cookies == null)
356 {
357 string text = Headers["Cookie"];
358 if (!string.IsNullOrEmpty(text))
359 {
361 }
362 if (_cookies == null)
363 {
365 }
366 }
367 return _cookies;
368 }
369 }
370
372 {
373 get
374 {
375 if (UserAgent != null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(UserAgent, "UP"))
376 {
377 string text = Headers["x-up-devcap-post-charset"];
378 if (text != null && text.Length > 0)
379 {
380 try
381 {
382 return Encoding.GetEncoding(text);
383 }
384 catch (ArgumentException)
385 {
386 }
387 }
388 }
389 if (HasEntityBody && ContentType != null)
390 {
392 if (charSetValueFromHeader != null)
393 {
394 try
395 {
397 }
398 catch (ArgumentException)
399 {
400 }
401 }
402 }
403 return Encoding.Default;
404 }
405 }
406
407 public string? ContentType => Headers["Content-Type"];
408
410
412 {
413 get
414 {
416 {
417 return false;
418 }
419 bool flag = false;
420 if (string.IsNullOrEmpty(Headers["Connection"]) || string.IsNullOrEmpty(Headers["Upgrade"]))
421 {
422 return false;
423 }
424 string[] values = Headers.GetValues("Connection");
425 foreach (string a in values)
426 {
427 if (string.Equals(a, "Upgrade", StringComparison.OrdinalIgnoreCase))
428 {
429 flag = true;
430 break;
431 }
432 }
433 if (!flag)
434 {
435 return false;
436 }
437 string[] values2 = Headers.GetValues("Upgrade");
438 foreach (string a2 in values2)
439 {
440 if (string.Equals(a2, "websocket", StringComparison.OrdinalIgnoreCase))
441 {
442 return true;
443 }
444 }
445 return false;
446 }
447 }
448
449 public bool KeepAlive
450 {
451 get
452 {
453 if (!_keepAlive.HasValue)
454 {
455 string text = Headers["Proxy-Connection"];
456 if (string.IsNullOrEmpty(text))
457 {
458 text = Headers["Connection"];
459 }
460 if (string.IsNullOrEmpty(text))
461 {
463 {
464 _keepAlive = true;
465 }
466 else
467 {
468 text = Headers["Keep-Alive"];
469 _keepAlive = !string.IsNullOrEmpty(text);
470 }
471 }
472 else
473 {
474 text = text.ToLowerInvariant();
475 _keepAlive = text.IndexOf("close", StringComparison.OrdinalIgnoreCase) < 0 || text.Contains("keep-alive", StringComparison.OrdinalIgnoreCase);
476 }
477 }
478 if (System.Net.NetEventSource.Log.IsEnabled())
479 {
480 bool? keepAlive = _keepAlive;
481 System.Net.NetEventSource.Info(this, "_keepAlive=" + keepAlive, "KeepAlive");
482 }
483 return _keepAlive.Value;
484 }
485 }
486
496
497 public string? RawUrl => _rawUrl;
498
499 private string RequestScheme
500 {
501 get
502 {
504 {
505 return "http";
506 }
507 return "https";
508 }
509 }
510
511 public string UserAgent => Headers["User-Agent"];
512
514
515 public string UserHostName => Headers["Host"];
516
518 {
519 get
520 {
521 string text = Headers["Referer"];
522 if (text == null)
523 {
524 return null;
525 }
526 if (!Uri.TryCreate(text, UriKind.RelativeOrAbsolute, out Uri result))
527 {
528 return null;
529 }
530 return result;
531 }
532 }
533
534 public Uri? Url => RequestUri;
535
537
539
540 internal X509Certificate2? ClientCertificate { get; set; }
541
543 {
544 get
545 {
546 if (ClientCertState == ListenerClientCertState.NotInitialized)
547 {
548 throw new InvalidOperationException(System.SR.Format(System.SR.net_listener_mustcall, "GetClientCertificate()/BeginGetClientCertificate()"));
549 }
551 {
552 throw new InvalidOperationException(System.SR.Format(System.SR.net_listener_mustcompletecall, "GetClientCertificate()/BeginGetClientCertificate()"));
553 }
555 }
556 }
557
559
561 {
562 get
563 {
566 }
567 }
568
570 {
571 get
572 {
575 }
576 }
577
578 internal ulong RequestId => _requestId;
579
581 {
582 get
583 {
584 Guid result = default(Guid);
585 *(ulong*)(8 + (byte*)(&result)) = RequestId;
586 return result;
587 }
588 }
589
590 public long ContentLength64
591 {
592 get
593 {
594 if (_boundaryType == BoundaryType.None)
595 {
596 string text = Headers["Transfer-Encoding"];
597 if (text != null && text.Equals("chunked", StringComparison.OrdinalIgnoreCase))
598 {
599 _boundaryType = BoundaryType.Chunked;
600 _contentLength = -1L;
601 }
602 else
603 {
604 _contentLength = 0L;
605 _boundaryType = BoundaryType.ContentLength;
606 string text2 = Headers["Content-Length"];
607 if (text2 != null && !long.TryParse(text2, NumberStyles.None, CultureInfo.InvariantCulture.NumberFormat, out _contentLength))
608 {
609 _contentLength = 0L;
610 _boundaryType = BoundaryType.Invalid;
611 }
612 }
613 }
614 if (System.Net.NetEventSource.Log.IsEnabled())
615 {
616 System.Net.NetEventSource.Info(this, $"_contentLength:{_contentLength} _boundaryType:{_boundaryType}", "ContentLength64");
617 }
618 return _contentLength;
619 }
620 }
621
622 public NameValueCollection Headers
623 {
624 get
625 {
626 if (_webHeaders == null)
627 {
628 _webHeaders = global::Interop.HttpApi.GetHeaders(RequestBuffer, OriginalBlobAddress);
629 }
630 if (System.Net.NetEventSource.Log.IsEnabled())
631 {
632 System.Net.NetEventSource.Info(this, $"webHeaders:{_webHeaders}", "Headers");
633 }
634 return _webHeaders;
635 }
636 }
637
638 public string HttpMethod
639 {
640 get
641 {
642 if (_httpMethod == null)
643 {
644 _httpMethod = global::Interop.HttpApi.GetVerb(RequestBuffer, OriginalBlobAddress);
645 }
646 if (System.Net.NetEventSource.Log.IsEnabled())
647 {
648 System.Net.NetEventSource.Info(this, $"_httpMethod:{_httpMethod}", "HttpMethod");
649 }
650 return _httpMethod;
651 }
652 }
653
655 {
656 get
657 {
658 if (_requestStream == null)
659 {
661 }
662 return _requestStream;
663 }
664 }
665
666 public bool IsAuthenticated
667 {
668 get
669 {
671 if (user != null && user.Identity != null)
672 {
673 return user.Identity.IsAuthenticated;
674 }
675 return false;
676 }
677 }
678
679 public bool IsSecureConnection => _sslStatus != SslStatus.Insecure;
680
681 public string? ServiceName
682 {
683 get
684 {
685 return _serviceName;
686 }
687 internal set
688 {
690 }
691 }
692
694
695 public bool HasEntityBody
696 {
697 get
698 {
699 if ((ContentLength64 <= 0 || _boundaryType != 0) && _boundaryType != BoundaryType.Chunked)
700 {
701 return _boundaryType == BoundaryType.Multipart;
702 }
703 return true;
704 }
705 }
706
708 {
709 get
710 {
711 if (_remoteEndPoint == null)
712 {
713 _remoteEndPoint = global::Interop.HttpApi.GetRemoteEndPoint(RequestBuffer, OriginalBlobAddress);
714 }
715 if (System.Net.NetEventSource.Log.IsEnabled())
716 {
717 System.Net.NetEventSource.Info(this, "_remoteEndPoint" + _remoteEndPoint, "RemoteEndPoint");
718 }
719 return _remoteEndPoint;
720 }
721 }
722
724 {
725 get
726 {
727 if (_localEndPoint == null)
728 {
729 _localEndPoint = global::Interop.HttpApi.GetLocalEndPoint(RequestBuffer, OriginalBlobAddress);
730 }
731 if (System.Net.NetEventSource.Log.IsEnabled())
732 {
733 System.Net.NetEventSource.Info(this, $"_localEndPoint={_localEndPoint}", "LocalEndPoint");
734 }
735 return _localEndPoint;
736 }
737 }
738
740 {
741 get
742 {
743 if (_requestUri == null)
744 {
746 }
747 if (System.Net.NetEventSource.Log.IsEnabled())
748 {
749 System.Net.NetEventSource.Info(this, $"_requestUri:{_requestUri}", "RequestUri");
750 }
751 return _requestUri;
752 }
753 }
754
756
758 {
759 if (System.Net.NetEventSource.Log.IsEnabled())
760 {
761 System.Net.NetEventSource.Info(this, "uri:" + uri?.ToString() + " setCookieHeader:" + setCookieHeader, "ParseCookies");
762 }
765 while (true)
766 {
767 Cookie server = cookieParser.GetServer();
768 if (server == null)
769 {
770 break;
771 }
772 if (System.Net.NetEventSource.Log.IsEnabled())
773 {
774 System.Net.NetEventSource.Info(this, "CookieParser returned cookie: " + server.ToString(), "ParseCookies");
775 }
776 if (server.Name.Length != 0)
777 {
778 cookieCollection.InternalAdd(server, isStrict: true);
779 }
780 }
781 return cookieCollection;
782 }
783
785 {
787 {
788 throw new InvalidOperationException(System.SR.Format(System.SR.net_listener_callinprogress, "GetClientCertificate()/BeginGetClientCertificate()"));
789 }
793 if (System.Net.NetEventSource.Log.IsEnabled())
794 {
795 System.Net.NetEventSource.Info(this, $"_clientCertificate:{ClientCertificate}", "GetClientCertificate");
796 }
797 return ClientCertificate;
798 }
799
801 {
802 if (System.Net.NetEventSource.Log.IsEnabled())
803 {
804 System.Net.NetEventSource.Info(this, null, "BeginGetClientCertificate");
805 }
807 {
808 throw new InvalidOperationException(System.SR.Format(System.SR.net_listener_callinprogress, "GetClientCertificate()/BeginGetClientCertificate()"));
809 }
812 }
813
815 {
816 return Task.Factory.FromAsync((AsyncCallback callback, object state) => ((HttpListenerRequest)state).BeginGetClientCertificate(callback, state), (IAsyncResult iar) => ((HttpListenerRequest)iar.AsyncState).EndGetClientCertificate(iar), this);
817 }
818
820 {
821 if (System.Net.NetEventSource.Log.IsEnabled())
822 {
823 System.Net.NetEventSource.Info(this, $"httpContext:${httpContext} memoryBlob {(IntPtr)memoryBlob.RequestBlob}", ".ctor");
825 }
829 _requestId = memoryBlob.RequestBlob->RequestId;
830 _connectionId = memoryBlob.RequestBlob->ConnectionId;
831 _sslStatus = ((memoryBlob.RequestBlob->pSslInfo != null) ? ((memoryBlob.RequestBlob->pSslInfo->SslClientCertNegotiated == 0) ? SslStatus.NoClientCert : SslStatus.ClientCert) : SslStatus.Insecure);
832 if (memoryBlob.RequestBlob->pRawUrl != null && memoryBlob.RequestBlob->RawUrlLength > 0)
833 {
834 _rawUrl = Marshal.PtrToStringAnsi((IntPtr)memoryBlob.RequestBlob->pRawUrl, memoryBlob.RequestBlob->RawUrlLength);
835 }
836 global::Interop.HttpApi.HTTP_COOKED_URL cookedUrl = memoryBlob.RequestBlob->CookedUrl;
837 if (cookedUrl.pHost != null && cookedUrl.HostLength > 0)
838 {
839 _cookedUrlHost = Marshal.PtrToStringUni((IntPtr)cookedUrl.pHost, cookedUrl.HostLength / 2);
840 }
841 if (cookedUrl.pAbsPath != null && cookedUrl.AbsPathLength > 0)
842 {
843 _cookedUrlPath = Marshal.PtrToStringUni((IntPtr)cookedUrl.pAbsPath, cookedUrl.AbsPathLength / 2);
844 }
845 if (cookedUrl.pQueryString != null && cookedUrl.QueryStringLength > 0)
846 {
847 _cookedUrlQuery = Marshal.PtrToStringUni((IntPtr)cookedUrl.pQueryString, cookedUrl.QueryStringLength / 2);
848 }
849 _version = new Version(memoryBlob.RequestBlob->Version.MajorVersion, memoryBlob.RequestBlob->Version.MinorVersion);
850 if (System.Net.NetEventSource.Log.IsEnabled())
851 {
852 System.Net.NetEventSource.Info(this, $"RequestId:{RequestId} ConnectionId:{_connectionId} RawConnectionId:{memoryBlob.RequestBlob->RawConnectionId} UrlContext:{memoryBlob.RequestBlob->UrlContext} RawUrl:{_rawUrl} Version:{_version} Secure:{_sslStatus}", ".ctor");
853 System.Net.NetEventSource.Info(this, $"httpContext:${httpContext} RequestUri:{RequestUri} Content-Length:{ContentLength64} HTTP Method:{HttpMethod}", ".ctor");
854 }
855 if (System.Net.NetEventSource.Log.IsEnabled())
856 {
857 StringBuilder stringBuilder = new StringBuilder("HttpListenerRequest Headers:\n");
858 for (int i = 0; i < Headers.Count; i++)
859 {
860 stringBuilder.Append('\t');
861 stringBuilder.Append(Headers.GetKey(i));
862 stringBuilder.Append(" : ");
863 stringBuilder.Append(Headers.Get(i));
864 stringBuilder.Append('\n');
865 }
866 System.Net.NetEventSource.Info(this, stringBuilder.ToString(), ".ctor");
867 }
868 }
869
871 {
872 if (memoryBlob != null && memoryBlob == _memoryBlob)
873 {
874 _memoryBlob = null;
875 }
876 }
877
878 internal void ReleasePins()
879 {
881 }
882
884 {
885 if (System.Net.NetEventSource.Log.IsEnabled())
886 {
887 System.Net.NetEventSource.Info(this, $"ClientCertificateError:{_clientCertificateError}", "GetClientCertificateErrorCore");
888 }
890 }
891
896
898 {
900 if (asyncResult == null)
901 {
902 throw new ArgumentNullException("asyncResult");
903 }
905 {
906 throw new ArgumentException(System.SR.net_io_invalidasyncresult, "asyncResult");
907 }
908 if (listenerClientCertAsyncResult.EndCalled)
909 {
910 throw new InvalidOperationException(System.SR.Format(System.SR.net_io_invalidendcall, "EndGetClientCertificate"));
911 }
912 listenerClientCertAsyncResult.EndCalled = true;
914 if (System.Net.NetEventSource.Log.IsEnabled())
915 {
916 System.Net.NetEventSource.Info(this, $"_clientCertificate:{ClientCertificate}", "EndGetClientCertificate");
917 }
918 return x509Certificate;
919 }
920
921 internal void Close()
922 {
924 if (memoryBlob != null)
925 {
926 memoryBlob.Close();
927 _memoryBlob = null;
928 }
929 _isDisposed = true;
930 }
931
933 {
935 if (_sslStatus != 0)
936 {
937 uint num = 1500u;
939 try
940 {
941 while (true)
942 {
943 if (System.Net.NetEventSource.Log.IsEnabled())
944 {
945 System.Net.NetEventSource.Info(this, "Calling Interop.HttpApi.HttpReceiveClientCertificate size:" + num, "BeginGetClientCertificateCore");
946 }
947 uint num2 = 0u;
948 uint num3 = global::Interop.HttpApi.HttpReceiveClientCertificate(HttpListenerContext.RequestQueueHandle, _connectionId, 0u, listenerClientCertAsyncResult.RequestBlob, num, &num2, listenerClientCertAsyncResult.NativeOverlapped);
949 if (System.Net.NetEventSource.Log.IsEnabled())
950 {
951 System.Net.NetEventSource.Info(this, "Call to Interop.HttpApi.HttpReceiveClientCertificate returned:" + num3 + " bytesReceived:" + num2, "BeginGetClientCertificateCore");
952 }
953 switch (num3)
954 {
955 case 234u:
956 break;
957 default:
958 throw new HttpListenerException((int)num3);
959 case 0u:
960 case 997u:
962 {
964 }
965 goto end_IL_0028;
966 }
967 global::Interop.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* requestBlob = listenerClientCertAsyncResult.RequestBlob;
968 num = num2 + requestBlob->CertEncodedSize;
970 continue;
972 break;
973 }
974 }
975 catch
976 {
977 listenerClientCertAsyncResult?.InternalCleanup();
978 throw;
979 }
980 }
981 else
982 {
984 listenerClientCertAsyncResult.InvokeCallback();
985 }
987 }
988
989 private unsafe void GetClientCertificateCore()
990 {
991 if (System.Net.NetEventSource.Log.IsEnabled())
992 {
993 System.Net.NetEventSource.Info(this, null, "GetClientCertificateCore");
994 }
995 if (_sslStatus == SslStatus.Insecure)
996 {
997 return;
998 }
999 uint num = 1500u;
1000 while (true)
1001 {
1002 byte[] array = new byte[checked((int)num)];
1003 fixed (byte* ptr = &array[0])
1004 {
1005 global::Interop.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* ptr2 = (global::Interop.HttpApi.HTTP_SSL_CLIENT_CERT_INFO*)ptr;
1006 if (System.Net.NetEventSource.Log.IsEnabled())
1007 {
1008 System.Net.NetEventSource.Info(this, "Calling Interop.HttpApi.HttpReceiveClientCertificate size:" + num, "GetClientCertificateCore");
1009 }
1010 uint num2 = 0u;
1011 uint num3 = global::Interop.HttpApi.HttpReceiveClientCertificate(HttpListenerContext.RequestQueueHandle, _connectionId, 0u, ptr2, num, &num2, null);
1012 if (System.Net.NetEventSource.Log.IsEnabled())
1013 {
1014 System.Net.NetEventSource.Info(this, "Call to Interop.HttpApi.HttpReceiveClientCertificate returned:" + num3 + " bytesReceived:" + num2, "GetClientCertificateCore");
1015 }
1016 switch (num3)
1017 {
1018 case 234u:
1019 num = num2 + ptr2->CertEncodedSize;
1020 break;
1021 case 0u:
1022 if (ptr2 == null)
1023 {
1024 return;
1025 }
1026 if (System.Net.NetEventSource.Log.IsEnabled())
1027 {
1028 System.Net.NetEventSource.Info(this, $"pClientCertInfo:{(IntPtr)ptr2} pClientCertInfo->CertFlags: {ptr2->CertFlags} pClientCertInfo->CertEncodedSize: {ptr2->CertEncodedSize} pClientCertInfo->pCertEncoded: {(IntPtr)ptr2->pCertEncoded} pClientCertInfo->Token: {(IntPtr)ptr2->Token} pClientCertInfo->CertDeniedByMapper: {ptr2->CertDeniedByMapper}", "GetClientCertificateCore");
1029 }
1030 if (ptr2->pCertEncoded != null)
1031 {
1032 try
1033 {
1034 byte[] array2 = new byte[ptr2->CertEncodedSize];
1035 Marshal.Copy((IntPtr)ptr2->pCertEncoded, array2, 0, array2.Length);
1037 }
1039 {
1040 if (System.Net.NetEventSource.Log.IsEnabled())
1041 {
1042 System.Net.NetEventSource.Info(this, $"CryptographicException={ex}", "GetClientCertificateCore");
1043 }
1044 }
1045 catch (SecurityException ex2)
1046 {
1047 if (System.Net.NetEventSource.Log.IsEnabled())
1048 {
1049 System.Net.NetEventSource.Info(this, $"SecurityException={ex2}", "GetClientCertificateCore");
1050 }
1051 }
1052 }
1053 _clientCertificateError = (int)ptr2->CertFlags;
1054 return;
1055 default:
1056 return;
1057 }
1058 }
1059 }
1060 }
1061
1066
1067 internal void CheckDisposed()
1068 {
1069 if (_isDisposed)
1070 {
1071 throw new ObjectDisposedException(GetType().FullName);
1072 }
1073 }
1074}
void Add(TKey key, TValue value)
static CultureInfo InvariantCulture
static int FromChar(int c)
static readonly Stream Null
Definition Stream.cs:488
override string ToString()
Definition Cookie.cs:607
ThreadPoolBoundHandle RequestQueueBoundHandle
static Uri GetRequestUri(string rawUri, string cookedUriScheme, string cookedUriHost, string cookedUriPath, string cookedUriQuery)
static void FillFromString(NameValueCollection nvc, string s, bool urlencoded, Encoding encoding)
static string UrlDecodeStringFromStringInternal(string s, Encoding e)
static string[] ParseMultivalueHeader(string s)
static string GetCharSetValueFromHeader(string headerValue)
unsafe HttpListenerRequest(HttpListenerContext httpContext, RequestContextBase memoryBlob)
IAsyncResult BeginGetClientCertificate(AsyncCallback? requestCallback, object? state)
X509Certificate2? EndGetClientCertificate(IAsyncResult asyncResult)
unsafe ListenerClientCertAsyncResult BeginGetClientCertificateCore(AsyncCallback requestCallback, object state)
CookieCollection ParseCookies(Uri uri, string setCookieHeader)
readonly HttpListenerContext _httpContext
ListenerClientCertState ClientCertState
void DetachBlob(RequestContextBase memoryBlob)
Task< X509Certificate2?> GetClientCertificateAsync()
void SetClientCertificateError(int clientCertificateError)
static readonly bool SkipIOCPCallbackOnSuccess
static unsafe ChannelBinding GetChannelBindingFromTls(HttpListenerSession session, ulong connectionId)
static readonly Version Version11
Definition HttpVersion.cs:9
override bool Equals([NotNullWhen(true)] object? comparand)
Definition IPAddress.cs:468
override string ToString()
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
static unsafe? string PtrToStringAnsi(IntPtr ptr)
Definition Marshal.cs:630
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string net_io_invalidendcall
Definition SR.cs:22
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_listener_mustcall
Definition SR.cs:32
static string net_listener_mustcompletecall
Definition SR.cs:84
static string net_io_invalidasyncresult
Definition SR.cs:20
static string net_listener_callinprogress
Definition SR.cs:88
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static Encoding Default
Definition Encoding.cs:345
virtual char[] GetChars(byte[] bytes)
Definition Encoding.cs:921
static new TaskFactory< TResult > Factory
Definition Task.cs:56
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
string Query
Definition Uri.cs:477
UriKind
Definition UriKind.cs:4