/// <summary> /// Sets an HTTP cookie to be sent with all requests made with this FlurlClient. /// </summary> /// <param name="name">cookie name.</param> /// <param name="value">cookie value.</param> /// <param name="expires">cookie expiration (optional). If excluded, cookie only lives for duration of session.</param> /// <returns>The modified FlurlClient.</returns> public static FlurlClient WithCookie(this FlurlClient client, string name, object value, DateTime?expires = null) { return(client.WithCookie(new Cookie(name, (value == null) ? null : value.ToInvariantString()) { Expires = expires ?? DateTime.MinValue })); }
/// <summary> /// Sets an HTTP cookie to be sent with all requests made with this FlurlClient. /// </summary> /// <param name="client">The client.</param> /// <param name="name">cookie name.</param> /// <param name="value">cookie value.</param> /// <param name="expires">cookie expiration (optional). If excluded, cookie only lives for duration of session.</param> /// <returns>The modified FlurlClient.</returns> /// <exception cref="ArgumentNullException"><paramref name="value" /> is null.</exception> public static FlurlClient WithCookie(this FlurlClient client, string name, object value, DateTime?expires = null) { var cookie = new Cookie(name, value?.ToInvariantString()) { Expires = expires ?? DateTime.MinValue }; return(client.WithCookie(cookie)); }
/// <summary> /// Sets HTTP cookies based on property names/values of the provided object, or keys/values if object is a dictionary, to be sent with all requests made with this FlurlClient. /// </summary> /// <param name="cookies">Names/values of HTTP cookies to set. Typically an anonymous object or IDictionary.</param> /// <param name="expires">Expiration for all cookies (optional). If excluded, cookies only live for duration of session.</param> /// <returns>The modified FlurlClient.</returns> public static FlurlClient WithCookies(this FlurlClient client, object cookies, DateTime? expires = null) { if (cookies == null) return client; foreach (var kv in cookies.ToKeyValuePairs()) client.WithCookie(kv.Key, kv.Value, expires); return client; }