ToServerString() private method

private ToServerString ( ) : string
return string
 internal void ComputeCookies()
 {
     if (NetEventSource.IsEnabled)
     {
         NetEventSource.Info(this,
                             $"Entering Set-Cookie: {Headers[HttpResponseHeader.SetCookie]}, Set-Cookie2: {Headers[HttpKnownHeaderNames.SetCookie2]}");
     }
     if (_cookies != null)
     {
         // now go through the collection, and concatenate all the cookies in per-variant strings
         string setCookie2 = null;
         string setCookie  = null;
         for (int index = 0; index < _cookies.Count; index++)
         {
             Cookie cookie       = _cookies[index];
             string cookieString = cookie.ToServerString();
             if (cookieString == null || cookieString.Length == 0)
             {
                 continue;
             }
             if (NetEventSource.IsEnabled)
             {
                 NetEventSource.Info(this, $"Now looking at index:{index} cookie: {cookie}");
             }
             if (cookie.IsRfc2965Variant())
             {
                 setCookie2 = setCookie2 == null ? cookieString : setCookie2 + ", " + cookieString;
             }
             else
             {
                 setCookie = setCookie == null ? cookieString : setCookie + ", " + cookieString;
             }
         }
         if (!string.IsNullOrEmpty(setCookie))
         {
             Headers.Set(HttpKnownHeaderNames.SetCookie, setCookie);
             if (string.IsNullOrEmpty(setCookie2))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie2);
             }
         }
         if (!string.IsNullOrEmpty(setCookie2))
         {
             Headers.Set(HttpKnownHeaderNames.SetCookie2, setCookie2);
             if (string.IsNullOrEmpty(setCookie))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie);
             }
         }
     }
     if (NetEventSource.IsEnabled)
     {
         NetEventSource.Info(this,
                             $"Exiting Set-Cookie: {Headers[HttpResponseHeader.SetCookie]} Set-Cookie2: {Headers[HttpKnownHeaderNames.SetCookie2]}");
     }
 }
Ejemplo n.º 2
0
 internal void ComputeCookies()
 {
     GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() entering Set-Cookie: " + ValidationHelper.ToString(Headers[HttpResponseHeader.SetCookie]) + " Set-Cookie2: " + ValidationHelper.ToString(Headers[HttpKnownHeaderNames.SetCookie2]));
     if (m_Cookies != null)
     {
         // now go through the collection, and concatenate all the cookies in per-variant strings
         string setCookie2 = null;
         string setCookie  = null;
         for (int index = 0; index < m_Cookies.Count; index++)
         {
             Cookie cookie       = m_Cookies[index];
             string cookieString = cookie.ToServerString();
             if (cookieString == null || cookieString.Length == 0)
             {
                 continue;
             }
             GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() now looking at index:" + index + " cookie.Variant:" + cookie.Variant + " cookie:" + cookie.ToString());
             if (cookie.Variant == CookieVariant.Rfc2965 || (HttpListenerContext.PromoteCookiesToRfc2965 && cookie.Variant == CookieVariant.Rfc2109))
             {
                 setCookie2 = setCookie2 == null ? cookieString : setCookie2 + ", " + cookieString;
             }
             else
             {
                 setCookie = setCookie == null ? cookieString : setCookie + ", " + cookieString;
             }
         }
         if (!string.IsNullOrEmpty(setCookie))
         {
             Headers.Set(HttpResponseHeader.SetCookie, setCookie);
             if (string.IsNullOrEmpty(setCookie2))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie2);
             }
         }
         if (!string.IsNullOrEmpty(setCookie2))
         {
             Headers.Set(HttpKnownHeaderNames.SetCookie2, setCookie2);
             if (string.IsNullOrEmpty(setCookie))
             {
                 Headers.Remove(HttpKnownHeaderNames.SetCookie);
             }
         }
     }
     GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::ComputeCookies() exiting Set-Cookie: " + ValidationHelper.ToString(Headers[HttpResponseHeader.SetCookie]) + " Set-Cookie2: " + ValidationHelper.ToString(Headers[HttpKnownHeaderNames.SetCookie2]));
 }
Ejemplo n.º 3
0
 internal void ComputeCookies()
 {
     if (this.m_Cookies != null)
     {
         string str  = null;
         string str2 = null;
         for (int i = 0; i < this.m_Cookies.Count; i++)
         {
             Cookie cookie = this.m_Cookies[i];
             string str3   = cookie.ToServerString();
             if ((str3 != null) && (str3.Length != 0))
             {
                 if ((cookie.Variant == CookieVariant.Rfc2965) || (this.HttpListenerContext.PromoteCookiesToRfc2965 && (cookie.Variant == CookieVariant.Rfc2109)))
                 {
                     str = (str == null) ? str3 : (str + ", " + str3);
                 }
                 else
                 {
                     str2 = (str2 == null) ? str3 : (str2 + ", " + str3);
                 }
             }
         }
         if (!string.IsNullOrEmpty(str2))
         {
             this.Headers.Set(HttpResponseHeader.SetCookie, str2);
             if (string.IsNullOrEmpty(str))
             {
                 this.Headers.Remove("Set-Cookie2");
             }
         }
         if (!string.IsNullOrEmpty(str))
         {
             this.Headers.Set("Set-Cookie2", str);
             if (string.IsNullOrEmpty(str2))
             {
                 this.Headers.Remove("Set-Cookie");
             }
         }
     }
 }