/// <summary> /// Creates a new FlurlResponse that wraps the give HttpResponseMessage. /// </summary> public FlurlResponse(HttpResponseMessage resp, CookieJar cookieJar = null) { ResponseMessage = resp; _headers = new Lazy <IReadOnlyNameValueList <string> >(LoadHeaders); _cookies = new Lazy <IReadOnlyList <FlurlCookie> >(LoadCookies); LoadCookieJar(cookieJar); }
private void LoadCookieJar(CookieJar jar) { if (jar == null) { return; } foreach (var cookie in Cookies) { jar.TryAddOrReplace(cookie, out _); // not added if cookie fails validation } }
/// <summary> /// Creates a new CookieJar and associates it with this request, which will be updated with any Set-Cookie /// headers present in the response and is suitable for reuse in subsequent requests. /// </summary> /// <param name="request">The IFlurlRequest.</param> /// <param name="cookieJar">The created CookieJar, which can be reused in subsequent requests.</param> /// <returns>This IFlurlClient instance.</returns> public static IFlurlRequest WithCookies(this IFlurlRequest request, out CookieJar cookieJar) { cookieJar = new CookieJar(); return(request.WithCookies(cookieJar)); }
/// <summary> /// Sets the CookieJar associated with this request, which will be updated with any Set-Cookie headers present /// in the response and is suitable for reuse in subsequent requests. /// </summary> /// <param name="request">The IFlurlRequest.</param> /// <param name="cookieJar">The CookieJar.</param> /// <returns>This IFlurlClient instance.</returns> public static IFlurlRequest WithCookies(this IFlurlRequest request, CookieJar cookieJar) { request.CookieJar = cookieJar; return(request); }