diff --git a/src/Flurl.Http.CodeGen/ExtensionMethodModel.cs b/src/Flurl.Http.CodeGen/ExtensionMethodModel.cs index 6fa88eb6..7a822602 100644 --- a/src/Flurl.Http.CodeGen/ExtensionMethodModel.cs +++ b/src/Flurl.Http.CodeGen/ExtensionMethodModel.cs @@ -9,7 +9,7 @@ public static IEnumerable GetAll() { return from httpVerb in new[] { null, "Get", "Post", "Head", "Put", "Delete", "Patch" } from bodyType in new[] { null, "Json", /*"Xml",*/ "String", "UrlEncoded" } - from extensionType in new[] { "FlurlClient", "Url", "string" } + from extensionType in new[] { "IFlurlClient", "Url", "string" } where SupportedCombo(httpVerb, bodyType, extensionType) from deserializeType in new[] { null, "Json", "JsonList", /*"Xml",*/ "String", "Stream", "Bytes" } where httpVerb == "Get" || deserializeType == null @@ -27,7 +27,7 @@ where AllowDeserializeToGeneric(deserializeType) || !isGeneric private static bool SupportedCombo(string verb, string bodyType, string extensionType) { switch (verb) { case null: // Send - return bodyType != null || extensionType != "FlurlClient"; + return bodyType != null || extensionType != "IFlurlClient"; case "Post": return true; case "Put": diff --git a/src/Flurl.Http.CodeGen/Program.cs b/src/Flurl.Http.CodeGen/Program.cs index 2c910e88..62234b13 100644 --- a/src/Flurl.Http.CodeGen/Program.cs +++ b/src/Flurl.Http.CodeGen/Program.cs @@ -66,14 +66,14 @@ private static void WriteExtensionMethods(CodeWriter writer) name = xm.Name; } writer.WriteLine("/// "); - var summaryStart = (xm.ExtentionOfType == "FlurlClient") ? "Sends" : "Creates a FlurlClient from the URL and sends"; + var summaryStart = (xm.ExtentionOfType == "IFlurlClient") ? "Sends" : "Creates a FlurlClient from the URL and sends"; if (xm.HttpVerb == null) writer.WriteLine("/// @0 an asynchronous request.", summaryStart); else writer.WriteLine("/// @0 an asynchronous @1 request.", summaryStart, xm.HttpVerb.ToUpperInvariant()); writer.WriteLine("/// "); - if (xm.ExtentionOfType == "FlurlClient") - writer.WriteLine("/// The Flurl client."); + if (xm.ExtentionOfType == "IFlurlClient") + writer.WriteLine("/// The IFlurlClient instance."); if (xm.ExtentionOfType == "Url" || xm.ExtentionOfType == "string") writer.WriteLine("/// The URL."); if (xm.HttpVerb == null) @@ -87,7 +87,7 @@ private static void WriteExtensionMethods(CodeWriter writer) writer.WriteLine("/// A Task whose result is @0.", xm.ReturnTypeDescription); var args = new List(); - args.Add("this " + xm.ExtentionOfType + (xm.ExtentionOfType == "FlurlClient" ? " client" : " url")); + args.Add("this " + xm.ExtentionOfType + (xm.ExtentionOfType == "IFlurlClient" ? " client" : " url")); if (xm.HttpVerb == null) args.Add("HttpMethod verb"); if (xm.BodyType != null) @@ -101,7 +101,7 @@ private static void WriteExtensionMethods(CodeWriter writer) writer.WriteLine("public static Task<@0> @1@2(@3) {", xm.TaskArg, xm.Name, xm.IsGeneric ? "" : "", string.Join(", ", args)); - if (xm.ExtentionOfType == "FlurlClient") + if (xm.ExtentionOfType == "IFlurlClient") { args.Clear(); args.Add( @@ -121,7 +121,7 @@ private static void WriteExtensionMethods(CodeWriter writer) xm.BodyType == "String" ? "data" : $"client.Settings.{xm.BodyType}Serializer.Serialize(data)"); } - var client = (xm.ExtentionOfType == "FlurlClient") ? "client" : "new FlurlClient(url, false)"; + var client = (xm.ExtentionOfType == "IFlurlClient") ? "client" : "new FlurlClient(url, false)"; var receive = (xm.DeserializeToType == null) ? "" : string.Format(".Receive{0}{1}()", xm.DeserializeToType, xm.IsGeneric ? "" : ""); writer.WriteLine("return @0.SendAsync(@1)@2;", client, string.Join(", ", args), receive); } diff --git a/src/Flurl.Http.Shared/ClientConfigExtensions.cs b/src/Flurl.Http.Shared/ClientConfigExtensions.cs index 067707d7..ede3fdd1 100644 --- a/src/Flurl.Http.Shared/ClientConfigExtensions.cs +++ b/src/Flurl.Http.Shared/ClientConfigExtensions.cs @@ -15,13 +15,13 @@ namespace Flurl.Http public static class ClientConfigExtensions { /// - /// Returns a new FlurlClient where all state (HttpClient, etc) is shared but with a different URL. + /// Returns a new IFlurlClient where all state (HttpClient, etc) is shared but with a different URL. /// Allows you to re-use the underlying HttpClient instance (such as to share cookies, etc) with /// different URLs in a thread-safe way. /// /// The client. /// The Url to call. - public static FlurlClient WithUrl(this FlurlClient client, Url url) { + public static IFlurlClient WithUrl(this IFlurlClient client, Url url) { var fc = client.Clone(); fc.Url = url; // prevent the new client from automatically disposing the parent's HttpClient @@ -30,22 +30,22 @@ public static FlurlClient WithUrl(this FlurlClient client, Url url) { } /// - /// Fluently specify that an existing FlurlClient should be used to call the Url, rather than creating a new one. + /// Fluently specify that an existing IFlurlClient should be used to call the Url, rather than creating a new one. /// Enables re-using the underlying HttpClient. /// /// The URL. - /// The FlurlClient to use in calling the Url - public static FlurlClient WithClient(this Url url, FlurlClient client) { + /// The IFlurlClient to use in calling the Url + public static IFlurlClient WithClient(this Url url, IFlurlClient client) { return client.WithUrl(url); } /// - /// Fluently specify that an existing FlurlClient should be used to call the Url, rather than creating a new one. + /// Fluently specify that an existing IFlurlClient should be used to call the Url, rather than creating a new one. /// Enables re-using the underlying HttpClient. /// /// The URL. - /// The FlurlClient to use in calling the Url - public static FlurlClient WithClient(this string url, FlurlClient client) { + /// The IFlurlClient to use in calling the Url + public static IFlurlClient WithClient(this string url, IFlurlClient client) { return client.WithUrl(url); } @@ -54,8 +54,8 @@ public static FlurlClient WithClient(this string url, FlurlClient client) { /// /// The client. /// Action defining the settings changes. - /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureClient(this FlurlClient client, Action action) { + /// The IFlurlClient with the modified HttpClient + public static IFlurlClient ConfigureClient(this IFlurlClient client, Action action) { action(client.Settings); return client; } @@ -65,8 +65,8 @@ public static FlurlClient ConfigureClient(this FlurlClient client, Action /// The URL. /// Action defining the settings changes. - /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureClient(this Url url, Action action) { + /// The IFlurlClient with the modified HttpClient + public static IFlurlClient ConfigureClient(this Url url, Action action) { return new FlurlClient(url, true).ConfigureClient(action); } @@ -76,7 +76,7 @@ public static FlurlClient ConfigureClient(this Url url, ActionThe URL. /// Action defining the settings changes. /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureClient(this string url, Action action) { + public static IFlurlClient ConfigureClient(this string url, Action action) { return new FlurlClient(url, true).ConfigureClient(action); } @@ -86,7 +86,7 @@ public static FlurlClient ConfigureClient(this string url, ActionThe client. /// Action to perform on the HttpClient. /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureHttpClient(this FlurlClient client, Action action) { + public static IFlurlClient ConfigureHttpClient(this IFlurlClient client, Action action) { action(client.HttpClient); return client; } @@ -97,7 +97,7 @@ public static FlurlClient ConfigureHttpClient(this FlurlClient client, ActionThe URL. /// Action to perform on the HttpClient. /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureHttpClient(this Url url, Action action) { + public static IFlurlClient ConfigureHttpClient(this Url url, Action action) { return new FlurlClient(url, true).ConfigureHttpClient(action); } @@ -107,7 +107,7 @@ public static FlurlClient ConfigureHttpClient(this Url url, Action a /// The URL. /// Action to perform on the HttpClient. /// The FlurlClient with the modified HttpClient - public static FlurlClient ConfigureHttpClient(this string url, Action action) { + public static IFlurlClient ConfigureHttpClient(this string url, Action action) { return new FlurlClient(url, true).ConfigureHttpClient(action); } @@ -117,7 +117,7 @@ public static FlurlClient ConfigureHttpClient(this string url, ActionThe client. /// Time to wait before the request times out. /// The modified FlurlClient. - public static FlurlClient WithTimeout(this FlurlClient client, TimeSpan timespan) { + public static IFlurlClient WithTimeout(this IFlurlClient client, TimeSpan timespan) { client.HttpClient.Timeout = timespan; return client; } @@ -128,7 +128,7 @@ public static FlurlClient WithTimeout(this FlurlClient client, TimeSpan timespan /// The URL. /// Time to wait before the request times out. /// The created FlurlClient. - public static FlurlClient WithTimeout(this Url url, TimeSpan timespan) { + public static IFlurlClient WithTimeout(this Url url, TimeSpan timespan) { return new FlurlClient(url, true).WithTimeout(timespan); } @@ -138,7 +138,7 @@ public static FlurlClient WithTimeout(this Url url, TimeSpan timespan) { /// The URL. /// Time to wait before the request times out. /// The created FlurlClient. - public static FlurlClient WithTimeout(this string url, TimeSpan timespan) { + public static IFlurlClient WithTimeout(this string url, TimeSpan timespan) { return new FlurlClient(url, true).WithTimeout(timespan); } @@ -149,7 +149,7 @@ public static FlurlClient WithTimeout(this string url, TimeSpan timespan) { /// Number of seconds to wait before the request times out. /// The modified FlurlClient. /// is less than or greater than .-or- is .-or- is . - public static FlurlClient WithTimeout(this FlurlClient client, int seconds) { + public static IFlurlClient WithTimeout(this IFlurlClient client, int seconds) { return client.WithTimeout(TimeSpan.FromSeconds(seconds)); } @@ -160,7 +160,7 @@ public static FlurlClient WithTimeout(this FlurlClient client, int seconds) { /// Number of seconds to wait before the request times out. /// The created FlurlClient. /// is less than or greater than .-or- is .-or- is . - public static FlurlClient WithTimeout(this Url url, int seconds) { + public static IFlurlClient WithTimeout(this Url url, int seconds) { return new FlurlClient(url, true).WithTimeout(seconds); } @@ -171,7 +171,7 @@ public static FlurlClient WithTimeout(this Url url, int seconds) { /// Number of seconds to wait before the request times out. /// The created FlurlClient. /// is less than or greater than .-or- is .-or- is . - public static FlurlClient WithTimeout(this string url, int seconds) { + public static IFlurlClient WithTimeout(this string url, int seconds) { return new FlurlClient(url, true).WithTimeout(seconds); } @@ -182,7 +182,7 @@ public static FlurlClient WithTimeout(this string url, int seconds) { /// HTTP header name. /// HTTP header value. /// The modified FlurlClient. - public static FlurlClient WithHeader(this FlurlClient client, string name, object value) { + public static IFlurlClient WithHeader(this IFlurlClient client, string name, object value) { var values = new[] { value?.ToString() }; client.HttpClient.DefaultRequestHeaders.Add(name, values); return client; @@ -195,7 +195,7 @@ public static FlurlClient WithHeader(this FlurlClient client, string name, objec /// HTTP header name. /// HTTP header value. /// The modified FlurlClient. - public static FlurlClient WithHeader(this Url url, string name, object value) { + public static IFlurlClient WithHeader(this Url url, string name, object value) { return new FlurlClient(url, true).WithHeader(name, value); } @@ -206,7 +206,7 @@ public static FlurlClient WithHeader(this Url url, string name, object value) { /// HTTP header name. /// HTTP header value. /// The modified FlurlClient. - public static FlurlClient WithHeader(this string url, string name, object value) { + public static IFlurlClient WithHeader(this string url, string name, object value) { return new FlurlClient(url, true).WithHeader(name, value); } @@ -216,7 +216,7 @@ public static FlurlClient WithHeader(this string url, string name, object value) /// The client. /// Names/values of HTTP headers to set. Typically an anonymous object or IDictionary. /// The modified FlurlClient. - public static FlurlClient WithHeaders(this FlurlClient client, object headers) { + public static IFlurlClient WithHeaders(this IFlurlClient client, object headers) { if (headers == null) return client; @@ -236,7 +236,7 @@ public static FlurlClient WithHeaders(this FlurlClient client, object headers) { /// The URL. /// Names/values of HTTP headers to set. Typically an anonymous object or IDictionary. /// The modified FlurlClient. - public static FlurlClient WithHeaders(this Url url, object headers) { + public static IFlurlClient WithHeaders(this Url url, object headers) { return new FlurlClient(url, true).WithHeaders(headers); } @@ -246,7 +246,7 @@ public static FlurlClient WithHeaders(this Url url, object headers) { /// The URL. /// Names/values of HTTP headers to set. Typically an anonymous object or IDictionary. /// The modified FlurlClient. - public static FlurlClient WithHeaders(this string url, object headers) { + public static IFlurlClient WithHeaders(this string url, object headers) { return new FlurlClient(url, true).WithHeaders(headers); } @@ -257,7 +257,7 @@ public static FlurlClient WithHeaders(this string url, object headers) { /// Username of authenticating user. /// Password of authenticating user. /// The modified FlurlClient. - public static FlurlClient WithBasicAuth(this FlurlClient client, string username, string password) { + public static IFlurlClient WithBasicAuth(this IFlurlClient client, string username, string password) { // http://stackoverflow.com/questions/14627399/setting-authorization-header-of-httpclient var value = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")); client.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", value); @@ -270,8 +270,8 @@ public static FlurlClient WithBasicAuth(this FlurlClient client, string username /// The URL. /// Username of authenticating user. /// Password of authenticating user. - /// The new FlurlClient. - public static FlurlClient WithBasicAuth(this Url url, string username, string password) { + /// The new IFlurlClient instance. + public static IFlurlClient WithBasicAuth(this Url url, string username, string password) { return new FlurlClient(url, true).WithBasicAuth(username, password); } @@ -281,8 +281,8 @@ public static FlurlClient WithBasicAuth(this Url url, string username, string pa /// The URL. /// Username of authenticating user. /// Password of authenticating user. - /// The new FlurlClient. - public static FlurlClient WithBasicAuth(this string url, string username, string password) { + /// The new IFlurlClient instance. + public static IFlurlClient WithBasicAuth(this string url, string username, string password) { return new FlurlClient(url, true).WithBasicAuth(username, password); } @@ -292,7 +292,7 @@ public static FlurlClient WithBasicAuth(this string url, string username, string /// The client. /// The acquired bearer token to pass. /// The modified FlurlClient. - public static FlurlClient WithOAuthBearerToken(this FlurlClient client, string token) { + public static IFlurlClient WithOAuthBearerToken(this IFlurlClient client, string token) { client.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); return client; } @@ -302,8 +302,8 @@ public static FlurlClient WithOAuthBearerToken(this FlurlClient client, string t /// /// The URL. /// The acquired bearer token to pass. - /// The new FlurlClient. - public static FlurlClient WithOAuthBearerToken(this Url url, string token) { + /// The new IFlurlClient instance. + public static IFlurlClient WithOAuthBearerToken(this Url url, string token) { return new FlurlClient(url, true).WithOAuthBearerToken(token); } @@ -312,8 +312,8 @@ public static FlurlClient WithOAuthBearerToken(this Url url, string token) { /// /// The URL. /// The acquired bearer token to pass. - /// The new FlurlClient. - public static FlurlClient WithOAuthBearerToken(this string url, string token) { + /// The new IFlurlClient instance. + public static IFlurlClient WithOAuthBearerToken(this string url, string token) { return new FlurlClient(url, true).WithOAuthBearerToken(token); } @@ -323,7 +323,7 @@ public static FlurlClient WithOAuthBearerToken(this string url, string token) { /// The client. /// Examples: "3xx", "100,300,600", "100-299,6xx" /// The modified FlurlClient. - public static FlurlClient AllowHttpStatus(this FlurlClient client, string pattern) { + public static IFlurlClient AllowHttpStatus(this IFlurlClient client, string pattern) { if (!string.IsNullOrWhiteSpace(pattern)) { var current = client.Settings.AllowedHttpStatusRange; if (string.IsNullOrWhiteSpace(current)) @@ -339,8 +339,8 @@ public static FlurlClient AllowHttpStatus(this FlurlClient client, string patter /// /// The URL. /// Examples: "3xx", "100,300,600", "100-299,6xx" - /// The new FlurlClient. - public static FlurlClient AllowHttpStatus(this Url url, string pattern) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowHttpStatus(this Url url, string pattern) { return new FlurlClient(url, true).AllowHttpStatus(pattern); } @@ -349,8 +349,8 @@ public static FlurlClient AllowHttpStatus(this Url url, string pattern) { /// /// The URL. /// Examples: "3xx", "100,300,600", "100-299,6xx" - /// The new FlurlClient. - public static FlurlClient AllowHttpStatus(this string url, string pattern) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowHttpStatus(this string url, string pattern) { return new FlurlClient(url, true).AllowHttpStatus(pattern); } @@ -360,7 +360,7 @@ public static FlurlClient AllowHttpStatus(this string url, string pattern) { /// The client. /// Examples: HttpStatusCode.NotFound /// The modified FlurlClient. - public static FlurlClient AllowHttpStatus(this FlurlClient client, params HttpStatusCode[] statusCodes) { + public static IFlurlClient AllowHttpStatus(this IFlurlClient client, params HttpStatusCode[] statusCodes) { var pattern = string.Join(",", statusCodes.Select(c => (int)c)); return AllowHttpStatus(client, pattern); } @@ -370,8 +370,8 @@ public static FlurlClient AllowHttpStatus(this FlurlClient client, params HttpSt /// /// The URL. /// Examples: HttpStatusCode.NotFound - /// The new FlurlClient. - public static FlurlClient AllowHttpStatus(this Url url, params HttpStatusCode[] statusCodes) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowHttpStatus(this Url url, params HttpStatusCode[] statusCodes) { return new FlurlClient(url, true).AllowHttpStatus(statusCodes); } @@ -380,16 +380,16 @@ public static FlurlClient AllowHttpStatus(this Url url, params HttpStatusCode[] /// /// The URL. /// Examples: HttpStatusCode.NotFound - /// The new FlurlClient. - public static FlurlClient AllowHttpStatus(this string url, params HttpStatusCode[] statusCodes) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowHttpStatus(this string url, params HttpStatusCode[] statusCodes) { return new FlurlClient(url, true).AllowHttpStatus(statusCodes); } /// /// Prevents a FlurlHttpException from being thrown on any completed response, regardless of the HTTP status code. /// - /// The modified FlurlClient. - public static FlurlClient AllowAnyHttpStatus(this FlurlClient client) { + /// The modified IFlurlClient. + public static IFlurlClient AllowAnyHttpStatus(this IFlurlClient client) { client.Settings.AllowedHttpStatusRange = "*"; return client; } @@ -397,16 +397,16 @@ public static FlurlClient AllowAnyHttpStatus(this FlurlClient client) { /// /// Creates a FlurlClient from the URL and prevents a FlurlHttpException from being thrown on any completed response, regardless of the HTTP status code. /// - /// The new FlurlClient. - public static FlurlClient AllowAnyHttpStatus(this Url url) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowAnyHttpStatus(this Url url) { return new FlurlClient(url, true).AllowAnyHttpStatus(); } /// /// Creates a FlurlClient from the URL and prevents a FlurlHttpException from being thrown on any completed response, regardless of the HTTP status code. /// - /// The new FlurlClient. - public static FlurlClient AllowAnyHttpStatus(this string url) { + /// The new IFlurlClient instance. + public static IFlurlClient AllowAnyHttpStatus(this string url) { return new FlurlClient(url, true).AllowAnyHttpStatus(); } } diff --git a/src/Flurl.Http.Shared/CookieExtensions.cs b/src/Flurl.Http.Shared/CookieExtensions.cs index 6fe312ba..52903884 100644 --- a/src/Flurl.Http.Shared/CookieExtensions.cs +++ b/src/Flurl.Http.Shared/CookieExtensions.cs @@ -18,7 +18,7 @@ public static class CookieExtensions /// /// Allows cookies to be sent and received in calls made with this client. Not necessary to call when setting cookies via WithCookie/WithCookies. /// - public static FlurlClient EnableCookies(this FlurlClient client) { + public static IFlurlClient EnableCookies(this IFlurlClient client) { client.Settings.CookiesEnabled = true; return client; } @@ -26,14 +26,14 @@ public static FlurlClient EnableCookies(this FlurlClient client) { /// /// Allows cookies to be sent and received in calls made to this Url. Not necessary to call when setting cookies via WithCookie/WithCookies. /// - public static FlurlClient EnableCookies(this Url url) { + public static IFlurlClient EnableCookies(this Url url) { return new FlurlClient(url).EnableCookies(); } /// /// Allows cookies to be sent and received in calls made to this Url. Not necessary to call when setting cookies via WithCookie/WithCookies. /// - public static FlurlClient EnableCookies(this string url) { + public static IFlurlClient EnableCookies(this string url) { return new FlurlClient(url).EnableCookies(); } @@ -44,7 +44,7 @@ public static FlurlClient EnableCookies(this string url) { /// The cookie to set. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this FlurlClient client, Cookie cookie) { + public static IFlurlClient WithCookie(this IFlurlClient client, Cookie cookie) { client.Settings.CookiesEnabled = true; client.Cookies[cookie.Name] = cookie; return client; @@ -57,7 +57,7 @@ public static FlurlClient WithCookie(this FlurlClient client, Cookie cookie) { /// the cookie to set. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this string url, Cookie cookie) { + public static IFlurlClient WithCookie(this string url, Cookie cookie) { return new FlurlClient(url, true).WithCookie(cookie); } @@ -68,7 +68,7 @@ public static FlurlClient WithCookie(this string url, Cookie cookie) { /// the cookie to set. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this Url url, Cookie cookie) { + public static IFlurlClient WithCookie(this Url url, Cookie cookie) { return new FlurlClient(url, true).WithCookie(cookie); } @@ -81,7 +81,7 @@ public static FlurlClient WithCookie(this Url url, Cookie cookie) { /// cookie expiration (optional). If excluded, cookie only lives for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this FlurlClient client, string name, object value, DateTime? expires = null) { + public static IFlurlClient WithCookie(this IFlurlClient client, string name, object value, DateTime? expires = null) { var cookie = new Cookie(name, value?.ToInvariantString()) { Expires = expires ?? DateTime.MinValue }; return client.WithCookie(cookie); } @@ -95,7 +95,7 @@ public static FlurlClient WithCookie(this FlurlClient client, string name, objec /// cookie expiration (optional). If excluded, cookie only lives for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this string url, string name, object value, DateTime? expires = null) { + public static IFlurlClient WithCookie(this string url, string name, object value, DateTime? expires = null) { return new FlurlClient(url, true).WithCookie(name, value, expires); } @@ -108,7 +108,7 @@ public static FlurlClient WithCookie(this string url, string name, object value, /// cookie expiration (optional). If excluded, cookie only lives for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookie(this Url url, string name, object value, DateTime? expires = null) { + public static IFlurlClient WithCookie(this Url url, string name, object value, DateTime? expires = null) { return new FlurlClient(url, true).WithCookie(name, value, expires); } @@ -120,7 +120,7 @@ public static FlurlClient WithCookie(this Url url, string name, object value, Da /// Expiration for all cookies (optional). If excluded, cookies only live for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookies(this FlurlClient client, object cookies, DateTime? expires = null) { + public static IFlurlClient WithCookies(this IFlurlClient client, object cookies, DateTime? expires = null) { if (cookies == null) return client; @@ -138,7 +138,7 @@ public static FlurlClient WithCookies(this FlurlClient client, object cookies, D /// Expiration for all cookies (optional). If excluded, cookies only live for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookies(this Url url, object cookies, DateTime? expires = null) { + public static IFlurlClient WithCookies(this Url url, object cookies, DateTime? expires = null) { return new FlurlClient(url, true).WithCookies(cookies); } @@ -150,7 +150,7 @@ public static FlurlClient WithCookies(this Url url, object cookies, DateTime? ex /// Expiration for all cookies (optional). If excluded, cookies only live for duration of session. /// The modified FlurlClient. /// is null. - public static FlurlClient WithCookies(this string url, object cookies, DateTime? expires = null) { + public static IFlurlClient WithCookies(this string url, object cookies, DateTime? expires = null) { return new FlurlClient(url, true).WithCookies(cookies); } } diff --git a/src/Flurl.Http.Shared/DownloadExtensions.cs b/src/Flurl.Http.Shared/DownloadExtensions.cs index 66beca09..6be61bb2 100644 --- a/src/Flurl.Http.Shared/DownloadExtensions.cs +++ b/src/Flurl.Http.Shared/DownloadExtensions.cs @@ -17,7 +17,7 @@ public static class DownloadExtensions /// Name of local file. If not specified, the source filename (last segment of the URL) is used. /// Buffer size in bytes. Default is 4096. /// A Task whose result is the local path of the downloaded file. - public static async Task DownloadFileAsync(this FlurlClient client, string localFolderPath, string localFileName = null, int bufferSize = 4096) { + public static async Task DownloadFileAsync(this IFlurlClient client, string localFolderPath, string localFileName = null, int bufferSize = 4096) { if (localFileName == null) localFileName = client.Url.Path.Split('/').Last(); diff --git a/src/Flurl.Http.Shared/FlurlClient.cs b/src/Flurl.Http.Shared/FlurlClient.cs index 2cbd7cd4..5c01c49f 100644 --- a/src/Flurl.Http.Shared/FlurlClient.cs +++ b/src/Flurl.Http.Shared/FlurlClient.cs @@ -10,10 +10,58 @@ namespace Flurl.Http { + /// + /// Interface defining FlurlClient's contract (useful for mocking and DI) + /// + public interface IFlurlClient : IDisposable { + /// + /// Creates a copy of this FlurlClient with a shared instance of HttpClient and HttpMessageHandler + /// + FlurlClient Clone(); + + /// + /// Gets or sets the FlurlHttpSettings object used by this client. + /// + FlurlHttpSettings Settings { get; set; } + + /// + /// Gets or sets the URL to be called. + /// + Url Url { get; set; } + + /// + /// Collection of HttpCookies sent and received. + /// + IDictionary Cookies { get; } + + /// + /// Gets the HttpClient to be used in subsequent HTTP calls. Creation (when necessary) is delegated + /// to FlurlHttp.HttpClientFactory. Reused for the life of the FlurlClient. + /// + HttpClient HttpClient { get; } + + /// + /// Gets the HttpMessageHandler to be used in subsequent HTTP calls. Creation (when necessary) is delegated + /// to FlurlHttp.HttpClientFactory. + /// + HttpMessageHandler HttpMessageHandler { get; } + + /// + /// Creates and asynchronously sends an HttpRequestMethod, disposing HttpClient if AutoDispose it true. + /// Mainly used to implement higher-level extension methods (GetJsonAsync, etc). + /// + /// The HTTP method used to make the request. + /// Contents of the request body. + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. + /// The HttpCompletionOption used in the request. Optional. + /// A Task whose result is the received HttpResponseMessage. + Task SendAsync(HttpMethod verb, HttpContent content = null, CancellationToken? cancellationToken = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead); + } + /// /// A chainable wrapper around HttpClient and Flurl.Url. /// - public class FlurlClient : IDisposable + public class FlurlClient : IFlurlClient { /// /// Initializes a new instance of the class. diff --git a/src/Flurl.Http.Shared/HttpExtensions.cs b/src/Flurl.Http.Shared/HttpExtensions.cs index 5bc6c347..9ddbc857 100644 --- a/src/Flurl.Http.Shared/HttpExtensions.cs +++ b/src/Flurl.Http.Shared/HttpExtensions.cs @@ -43,13 +43,13 @@ public static class HttpExtensions /// /// Sends an asynchronous request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// The HTTP method used to make the request. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task SendJsonAsync(this FlurlClient client, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task SendJsonAsync(this IFlurlClient client, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedJsonContent(client.Settings.JsonSerializer.Serialize(data)); return client.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -83,13 +83,13 @@ public static class HttpExtensions /// /// Sends an asynchronous request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// The HTTP method used to make the request. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task SendStringAsync(this FlurlClient client, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task SendStringAsync(this IFlurlClient client, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedStringContent(data); return client.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -123,13 +123,13 @@ public static class HttpExtensions /// /// Sends an asynchronous request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// The HTTP method used to make the request. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task SendUrlEncodedAsync(this FlurlClient client, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task SendUrlEncodedAsync(this IFlurlClient client, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedUrlEncodedContent(client.Settings.UrlEncodedSerializer.Serialize(data)); return client.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -163,77 +163,77 @@ public static class HttpExtensions /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task GetAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the JSON response body deserialized to an object of type T. - public static Task GetJsonAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetJsonAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveJson(); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the JSON response body deserialized to a dynamic. - public static Task GetJsonAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetJsonAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveJson(); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the JSON response body deserialized to a list of dynamics. - public static Task> GetJsonListAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task> GetJsonListAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveJsonList(); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the response body as a string. - public static Task GetStringAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetStringAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveString(); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the response body as a Stream. - public static Task GetStreamAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetStreamAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveStream(); } /// /// Sends an asynchronous GET request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the response body as a byte array. - public static Task GetBytesAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task GetBytesAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveBytes(); } @@ -394,12 +394,12 @@ public static class HttpExtensions /// /// Sends an asynchronous POST request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PostAsync(this FlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PostAsync(this IFlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -430,12 +430,12 @@ public static class HttpExtensions /// /// Sends an asynchronous POST request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PostJsonAsync(this FlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PostJsonAsync(this IFlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedJsonContent(client.Settings.JsonSerializer.Serialize(data)); return client.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -467,12 +467,12 @@ public static class HttpExtensions /// /// Sends an asynchronous POST request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PostStringAsync(this FlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PostStringAsync(this IFlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedStringContent(data); return client.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -504,12 +504,12 @@ public static class HttpExtensions /// /// Sends an asynchronous POST request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PostUrlEncodedAsync(this FlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PostUrlEncodedAsync(this IFlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedUrlEncodedContent(client.Settings.UrlEncodedSerializer.Serialize(data)); return client.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -541,11 +541,11 @@ public static class HttpExtensions /// /// Sends an asynchronous HEAD request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task HeadAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task HeadAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Head, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -574,12 +574,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PUT request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PutAsync(this FlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PutAsync(this IFlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -610,12 +610,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PUT request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PutJsonAsync(this FlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PutJsonAsync(this IFlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedJsonContent(client.Settings.JsonSerializer.Serialize(data)); return client.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -647,12 +647,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PUT request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PutStringAsync(this FlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PutStringAsync(this IFlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedStringContent(data); return client.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -684,11 +684,11 @@ public static class HttpExtensions /// /// Sends an asynchronous DELETE request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task DeleteAsync(this FlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task DeleteAsync(this IFlurlClient client, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(HttpMethod.Delete, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -717,12 +717,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PATCH request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PatchAsync(this FlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PatchAsync(this IFlurlClient client, HttpContent content, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { return client.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -753,12 +753,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PATCH request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PatchJsonAsync(this FlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PatchJsonAsync(this IFlurlClient client, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedJsonContent(client.Settings.JsonSerializer.Serialize(data)); return client.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); } @@ -790,12 +790,12 @@ public static class HttpExtensions /// /// Sends an asynchronous PATCH request. /// - /// The Flurl client. + /// The IFlurlClient instance. /// Contents of the request body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received HttpResponseMessage. - public static Task PatchStringAsync(this FlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public static Task PatchStringAsync(this IFlurlClient client, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { var content = new CapturedStringContent(data); return client.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); } diff --git a/src/Flurl.Http.Shared/MultipartExtensions.cs b/src/Flurl.Http.Shared/MultipartExtensions.cs index 8703774c..ec05a6d0 100644 --- a/src/Flurl.Http.Shared/MultipartExtensions.cs +++ b/src/Flurl.Http.Shared/MultipartExtensions.cs @@ -18,7 +18,7 @@ public static class MultipartExtensions /// The Flurl client. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A Task whose result is the received HttpResponseMessage. - public static Task PostMultipartAsync(this FlurlClient client, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task PostMultipartAsync(this IFlurlClient client, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { var cmc = new CapturedMultipartContent(client.Settings); buildContent(cmc); return client.SendAsync(HttpMethod.Post, cmc, cancellationToken);