Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CookieCutter()

CookieCollection System.Net.CookieContainer.CookieCutter ( Uri uri,
string headerName,
string setCookieHeader,
bool isThrow )
inlinepackage

Definition at line 517 of file CookieContainer.cs.

518 {
519 if (NetEventSource.Log.IsEnabled())
520 {
521 NetEventSource.Info(this, $"uri:{uri} headerName:{headerName} setCookieHeader:{setCookieHeader} isThrow:{isThrow}", "CookieCutter");
522 }
523 CookieCollection cookieCollection = new CookieCollection();
524 CookieVariant variant = CookieVariant.Unknown;
525 if (headerName == null)
526 {
527 variant = CookieVariant.Rfc2109;
528 }
529 else
530 {
531 for (int i = 0; i < s_headerInfo.Length; i++)
532 {
533 if (string.Equals(headerName, s_headerInfo[i].Name, StringComparison.OrdinalIgnoreCase))
534 {
535 variant = s_headerInfo[i].Variant;
536 }
537 }
538 }
539 bool isLocalDomain = IsLocalDomain(uri.Host);
540 try
541 {
542 CookieParser cookieParser = new CookieParser(setCookieHeader);
543 while (true)
544 {
545 Cookie cookie = cookieParser.Get();
546 if (NetEventSource.Log.IsEnabled())
547 {
548 NetEventSource.Info(this, $"CookieParser returned cookie:{cookie}", "CookieCutter");
549 }
550 if (cookie == null)
551 {
552 if (cookieParser.EndofHeader())
553 {
554 break;
555 }
556 }
557 else if (string.IsNullOrEmpty(cookie.Name))
558 {
559 if (isThrow)
560 {
561 throw new CookieException(System.SR.net_cookie_format);
562 }
563 }
564 else if (cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, setDefault: true, isThrow))
565 {
566 cookieCollection.InternalAdd(cookie, isStrict: true);
567 }
568 }
569 }
570 catch (OutOfMemoryException)
571 {
572 throw;
573 }
574 catch (Exception inner)
575 {
576 if (isThrow)
577 {
578 throw new CookieException(System.SR.Format(System.SR.net_cookie_parse_header, uri.AbsoluteUri), inner);
579 }
580 }
582 for (int j = 0; j < count; j++)
583 {
585 }
586 return cookieCollection;
587 }
bool IsLocalDomain(string host)
static readonly HeaderVariantInfo[] s_headerInfo
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_cookie_parse_header
Definition SR.cs:34
static string net_cookie_format
Definition SR.cs:38
Definition SR.cs:7

References System.Uri.AbsoluteUri, System.Add, System.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Net.Equals, System.SR.Format(), System.Uri.Host, System.Net.NetEventSource.Info(), System.Net.CookieContainer.IsLocalDomain(), System.Net.NetEventSource.Log, System.Net.CookieContainer.m_fqdnMyDomain, System.Name, System.SR.net_cookie_format, System.SR.net_cookie_parse_header, and System.Net.CookieContainer.s_headerInfo.

Referenced by System.Net.CookieContainer.SetCookies().