internal void FillInCookiesCollection(HttpCookieCollection cookieCollection, bool includeResponse) { if (_wr == null) return; String s = _wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderCookie); // Parse the cookie server variable. // Format: c1=k1=v1&k2=v2; c2=... int l = (s != null) ? s.Length : 0; int i = 0; int j; char ch; HttpCookie lastCookie = null; while (i < l) { // find next ';' (don't look to ',' as per 91884) j = i; while (j < l) { ch = s[j]; if (ch == ';') break; j++; } // create cookie form string String cookieString = s.Substring(i, j-i).Trim(); i = j+1; // next cookie start if (cookieString.Length == 0) continue; HttpCookie cookie = CreateCookieFromString(cookieString); // some cookies starting with '$' are really attributes of the last cookie if (lastCookie != null) { String name = cookie.Name; // add known attribute to the last cookie (if any) if (name != null && name.Length > 0 && name[0] == '$') { if (StringUtil.EqualsIgnoreCase(name, "$Path")) lastCookie.Path = cookie.Value; else if (StringUtil.EqualsIgnoreCase(name, "$Domain")) lastCookie.Domain = cookie.Value; continue; } } // regular cookie cookieCollection.AddCookie(cookie, true); lastCookie = cookie; // goto next cookie } // Append response cookies if (includeResponse) { // If we have a reference to the response cookies collection, use it directly // rather than going through the Response object (which might not be available, e.g. // if we have already transitioned to a WebSockets request). HttpCookieCollection storedResponseCookies = _storedResponseCookies; if (storedResponseCookies == null && !HasTransitionedToWebSocketRequest && Response != null) { storedResponseCookies = Response.GetCookiesNoCreate(); } if (storedResponseCookies != null && storedResponseCookies.Count > 0) { HttpCookie[] responseCookieArray = new HttpCookie[storedResponseCookies.Count]; storedResponseCookies.CopyTo(responseCookieArray, 0); for (int iCookie = 0; iCookie < responseCookieArray.Length; iCookie++) cookieCollection.AddCookie(responseCookieArray[iCookie], append: true); } // release any stored reference to the response cookie collection _storedResponseCookies = null; } }
internal void FillInCookiesCollection(HttpCookieCollection cookieCollection, bool includeResponse) { if (this._wr != null) { string knownRequestHeader = this._wr.GetKnownRequestHeader(0x19); int num = (knownRequestHeader != null) ? knownRequestHeader.Length : 0; int startIndex = 0; HttpCookie cookie = null; while (startIndex < num) { int num3 = startIndex; while (num3 < num) { char ch = knownRequestHeader[num3]; if (ch == ';') { break; } num3++; } string s = knownRequestHeader.Substring(startIndex, num3 - startIndex).Trim(); startIndex = num3 + 1; if (s.Length != 0) { HttpCookie cookie2 = CreateCookieFromString(s); if (cookie != null) { string name = cookie2.Name; if (((name != null) && (name.Length > 0)) && (name[0] == '$')) { if (StringUtil.EqualsIgnoreCase(name, "$Path")) { cookie.Path = cookie2.Value; } else if (StringUtil.EqualsIgnoreCase(name, "$Domain")) { cookie.Domain = cookie2.Value; } continue; } } cookieCollection.AddCookie(cookie2, true); cookie = cookie2; } } if (includeResponse && (this.Response != null)) { HttpCookieCollection cookies = this.Response.Cookies; if (cookies.Count > 0) { HttpCookie[] dest = new HttpCookie[cookies.Count]; cookies.CopyTo(dest, 0); for (int i = 0; i < dest.Length; i++) { cookieCollection.AddCookie(dest[i], true); } } } } }