private VerifySetDefaults ( CookieVariant variant, Uri uri, bool isLocalDomain, string localDomain, bool setDefault, bool shouldThrow ) : bool | ||
variant | CookieVariant | |
uri | Uri | |
isLocalDomain | bool | |
localDomain | string | |
setDefault | bool | |
shouldThrow | bool | |
return | bool |
public void Add(Cookie cookie) { Uri uri; if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain"); } StringBuilder builder = new StringBuilder(); builder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter); if (!cookie.DomainImplicit && (cookie.Domain[0] == '.')) { builder.Append("0"); } builder.Append(cookie.Domain); if (cookie.PortList != null) { builder.Append(":").Append(cookie.PortList[0]); } builder.Append(cookie.Path); if (!Uri.TryCreate(builder.ToString(), UriKind.Absolute, out uri)) { throw new CookieException(SR.GetString("net_cookie_attribute", new object[] { "Domain", cookie.Domain })); } Cookie cookie2 = cookie.Clone(); cookie2.VerifySetDefaults(cookie2.Variant, uri, this.IsLocalDomain(uri.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie2, true); }
public void Add(Uri uri, Cookie cookie) { ArgumentNullException.ThrowIfNull(uri); ArgumentNullException.ThrowIfNull(cookie); Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
// This method will construct a faked URI: the Domain property is required for param. public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException(nameof(cookie)); } if (cookie.Domain.Length == 0) { throw new ArgumentException( SR.Format(SR.net_emptystringcall, nameof(cookie) + "." + nameof(cookie.Domain)), nameof(cookie) + "." + nameof(cookie.Domain)); } Uri uri; var uriSb = new StringBuilder(); // We cannot add an invalid cookie into the container. // Trying to prepare Uri for the cookie verification. uriSb.Append(cookie.Secure ? UriScheme.Https : UriScheme.Http).Append(UriScheme.SchemeDelimiter); // If the original cookie has an explicitly set domain, copy it over to the new cookie. if (!cookie.DomainImplicit) { if (cookie.Domain[0] == '.') { uriSb.Append("0"); // URI cctor should consume this faked host. } } uriSb.Append(cookie.Domain); // Either keep Port as implicit or set it according to original cookie. if (cookie.PortList != null) { uriSb.Append(":").Append(cookie.PortList[0]); } // Path must be present, set to root by default. uriSb.Append(cookie.Path); if (!Uri.TryCreate(uriSb.ToString(), UriKind.Absolute, out uri)) { throw new CookieException(SR.Format(SR.net_cookie_attribute, "Domain", cookie.Domain)); } // We don't know cookie verification status, so re-create the cookie and verify it. Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
// methods /// <include file='doc\cookiecontainer.uex' path='docs/doc[@for="CookieContainer.Add"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> //This method will construct faked URI, Domain property is required for param. public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException("cookie.Domain"); } // We don't know cookie verification status -> re-create cookie and verify it Cookie new_cookie = new Cookie(cookie.Name, cookie.Value); Uri uri; new_cookie.Version = cookie.Version; // We cannot add an invalid cookie into the container. // Trying to prepare Uri for the cookie verification string uriStr = (cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp) + Uri.SchemeDelimiter; if (cookie.Domain[0] == '.') { uriStr += "0"; // Uri cctor should eat this, faked host. new_cookie.Domain = cookie.Domain; // Otherwise keep Domain as implicitly set } uriStr += cookie.Domain; // Either keep Port as implici or set it according to original cookie if (cookie.PortList != null) { new_cookie.Port = cookie.Port; uriStr += ":" + cookie.PortList[0]; } // Path must be present, set to root by default new_cookie.Path = cookie.Path.Length == 0 ? "/" : cookie.Path; uriStr += cookie.Path; try { uri = new Uri(uriStr, false); } catch { throw new CookieException(SR.GetString(SR.net_cookie_attribute, "Domain", cookie.Domain)); } new_cookie.VerifySetDefaults(CookieVariant.Unknown, uri, IsLocal(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
/// <include file='doc\cookiecontainer.uex' path='docs/doc[@for="CookieContainer.Add2"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookie == null) { throw new ArgumentNullException("cookie"); } cookie.VerifySetDefaults(CookieVariant.Unknown, uri, IsLocal(uri.Host), m_fqdnMyDomain, true, true); Add(cookie, true); }
public void Add(Uri uri, CookieCollection cookies) { ArgumentNullException.ThrowIfNull(uri); ArgumentNullException.ThrowIfNull(cookies); bool isLocalDomain = IsLocalDomain(uri.Host); foreach (Cookie c in cookies) { Cookie new_cookie = c.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, isLocalDomain, m_fqdnMyDomain, true, true); Add(new_cookie, true); } }
public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookie == null) { throw new ArgumentNullException("cookie"); } Cookie cookie2 = cookie.Clone(); cookie2.VerifySetDefaults(cookie2.Variant, uri, this.IsLocalDomain(uri.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie2, true); }
public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (cookie == null) { throw new ArgumentNullException(nameof(cookie)); } Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
public void Add(Uri uri, CookieCollection cookies) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookies == null) { throw new ArgumentNullException("cookies"); } bool isLocalDomain = this.IsLocalDomain(uri.Host); foreach (Cookie cookie in cookies) { Cookie cookie2 = cookie.Clone(); cookie2.VerifySetDefaults(cookie2.Variant, uri, isLocalDomain, this.m_fqdnMyDomain, true, true); this.Add(cookie2, true); } }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(Uri uri, CookieCollection cookies) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookies == null) { throw new ArgumentNullException("cookies"); } bool isLocalDomain = IsLocalDomain(uri.Host); foreach (Cookie c in cookies) { Cookie new_cookie = c.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, isLocalDomain, m_fqdnMyDomain, true, true); Add(new_cookie, true); } }
/// <summary> /// Добавляет <see cref="T:System.Net.Cookie"/> в <see cref="T:System.Net.CookieContainer"/>.В этом методе используется домен из класса <see cref="T:System.Net.Cookie"/> для определения доменной коллекции, которую требуется связать с <see cref="T:System.Net.Cookie"/>. /// </summary> /// <param name="cookie">Объект <see cref="T:System.Net.Cookie"/>, добавляемый в <see cref="T:System.Net.CookieContainer"/>. </param><exception cref="T:System.ArgumentNullException">Значение параметра <paramref name="cookie"/> — null. </exception><exception cref="T:System.ArgumentException">Домен для <paramref name="cookie"/> равен null или пустой строке (""). </exception><exception cref="T:System.Net.CookieException">Значение <paramref name="cookie"/> больше, чем значение <paramref name="maxCookieSize"/>–или– домен для <paramref name="cookie"/> не является допустимым URI. </exception><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain"); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter); if (!cookie.DomainImplicit && (int)cookie.Domain[0] == 46) { stringBuilder.Append("0"); } stringBuilder.Append(cookie.Domain); if (cookie.PortList != null) { stringBuilder.Append(":").Append(cookie.PortList[0]); } stringBuilder.Append(cookie.Path); Uri result; if (!Uri.TryCreate(((object)stringBuilder).ToString(), UriKind.Absolute, out result)) { throw new CookieException(SR.GetString("net_cookie_attribute", (object)"Domain", (object)cookie.Domain)); } else { Cookie cookie1 = cookie.Clone(); cookie1.VerifySetDefaults(cookie1.Variant, result, this.IsLocalDomain(result.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie1, true); } }
internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow) { if (NetEventSource.IsEnabled) { if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"uri:{uri} headerName:{headerName} setCookieHeader:{setCookieHeader} isThrow:{isThrow}"); } } CookieCollection cookies = new CookieCollection(); CookieVariant variant = CookieVariant.Unknown; if (headerName == null) { variant = CookieVariant.Default; } else { for (int i = 0; i < s_headerInfo.Length; ++i) { if ((String.Compare(headerName, s_headerInfo[i].Name, StringComparison.OrdinalIgnoreCase) == 0)) { variant = s_headerInfo[i].Variant; } } } bool isLocalDomain = IsLocalDomain(uri.Host); try { CookieParser parser = new CookieParser(setCookieHeader); do { Cookie cookie = parser.Get(); if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"CookieParser returned cookie:{cookie}"); } if (cookie == null) { break; } // Parser marks invalid cookies this way if (String.IsNullOrEmpty(cookie.Name)) { if (isThrow) { throw new CookieException(SR.net_cookie_format); } // Otherwise, ignore (reject) cookie continue; } // This will set the default values from the response URI // AND will check for cookie validity if (!cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, true, isThrow)) { continue; } // If many same cookies arrive we collapse them into just one, hence setting // parameter isStrict = true below cookies.InternalAdd(cookie, true); } while (true); } catch (OutOfMemoryException) { throw; } catch (Exception e) { if (isThrow) { throw new CookieException(SR.Format(SR.net_cookie_parse_header, uri.AbsoluteUri), e); } } foreach (Cookie c in cookies) { Add(c, isThrow); } return(cookies); }
internal CookieCollection CookieCutter(Uri uri, string HeaderName, string setCookieHeader, bool isThrow) { CookieCollection cookies = new CookieCollection(); CookieVariant variant = CookieVariant.Unknown; if (HeaderName == null) { variant = CookieVariant.Default; } else { for (int i = 0; i < HeaderInfo.Length; ++i) { if ((String.Compare(HeaderName, HeaderInfo[i].Name, true, CultureInfo.InvariantCulture) == 0)) { variant = HeaderInfo[i].Variant; } } } bool isLocalDomain = IsLocal(uri.Host); try { CookieParser parser = new CookieParser(setCookieHeader); do { Cookie cookie = parser.Get(); if (cookie == null) { //Console.WriteLine("CookieCutter: eof cookies"); break; } //Parser marks invalid cookies this way if (cookie.Name == string.Empty) { if (isThrow) { throw new CookieException(SR.GetString(SR.net_cookie_format)); } //Otherwise, ignore (reject) cookie continue; } // this will set the default values from the response URI // AND will check for cookie validity if (!cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, true, isThrow)) { continue; } // If many same cookies arrive we collapse them into just one, hence setting // parameter isStrict = true below cookies.InternalAdd(cookie, true); } while (true); } catch (Exception e) { if (isThrow) { throw new CookieException(SR.GetString(SR.net_cookie_parse_header, uri.AbsoluteUri), e); } } foreach (Cookie c in cookies) { Add(c, isThrow); } return(cookies); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException("uri"); } if(cookie == null) { throw new ArgumentNullException("cookie"); } cookie.VerifySetDefaults(CookieVariant.Unknown, uri, IsLocal(uri.Host), m_fqdnMyDomain, true, true); Add(cookie, true); }
// methods /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> //This method will construct faked URI, Domain property is required for param. public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.GetString(SR.net_emptystringcall), "cookie.Domain"); } // We don't know cookie verification status -> re-create cookie and verify it Cookie new_cookie = new Cookie(cookie.Name, cookie.Value); Uri uri; new_cookie.Version = cookie.Version; // We cannot add an invalid cookie into the container. // Trying to prepare Uri for the cookie verification string uriStr = (cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp) + Uri.SchemeDelimiter ; if (cookie.Domain[0] == '.') { uriStr += "0"; // Uri cctor should eat this, faked host. new_cookie.Domain = cookie.Domain; // Otherwise keep Domain as implicitly set } uriStr += cookie.Domain; // Either keep Port as implici or set it according to original cookie if (cookie.PortList != null) { new_cookie.Port = cookie.Port; uriStr += ":"+ cookie.PortList[0]; } // Path must be present, set to root by default new_cookie.Path = cookie.Path.Length == 0 ? "/" : cookie.Path; uriStr += cookie.Path; if(!Uri.TryCreate(uriStr, UriKind.Absolute, out uri)) throw new CookieException(SR.GetString(SR.net_cookie_attribute, "Domain", cookie.Domain)); new_cookie.VerifySetDefaults(CookieVariant.Unknown, uri, IsLocal(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow) { GlobalLog.Print("CookieContainer#" + ValidationHelper.HashString(this) + "::CookieCutter() uri:" + uri + " headerName:" + headerName + " setCookieHeader:" + setCookieHeader + " isThrow:" + isThrow); CookieCollection cookies = new CookieCollection(); CookieVariant variant = CookieVariant.Unknown; if (headerName == null) { variant = CookieVariant.Default; } else { for (int i = 0; i < HeaderInfo.Length; ++i) { if ((String.Compare(headerName, HeaderInfo[i].Name, StringComparison.OrdinalIgnoreCase) == 0)) { variant = HeaderInfo[i].Variant; } } } bool isLocalDomain = IsLocalDomain(uri.Host); try { CookieParser parser = new CookieParser(setCookieHeader); do { Cookie cookie = parser.Get(); GlobalLog.Print("CookieContainer#" + ValidationHelper.HashString(this) + "::CookieCutter() CookieParser returned cookie:" + ValidationHelper.ToString(cookie)); if (cookie == null) { break; } //Parser marks invalid cookies this way if (ValidationHelper.IsBlankString(cookie.Name)) { if (isThrow) { throw new CookieException(SR.GetString(SR.net_cookie_format)); } //Otherwise, ignore (reject) cookie continue; } // this will set the default values from the response URI // AND will check for cookie validity if (!cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, true, isThrow)) { continue; } // If many same cookies arrive we collapse them into just one, hence setting // parameter isStrict = true below cookies.InternalAdd(cookie, true); } while (true); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } if (isThrow) { throw new CookieException(SR.GetString(SR.net_cookie_parse_header, uri.AbsoluteUri), e); } } foreach (Cookie c in cookies) { Add(c, isThrow); } return(cookies); }