diff --git a/Test/Flurl.Test/Http/RealHttpTests.cs b/Test/Flurl.Test/Http/RealHttpTests.cs index cb50f9fb..6f68ad60 100644 --- a/Test/Flurl.Test/Http/RealHttpTests.cs +++ b/Test/Flurl.Test/Http/RealHttpTests.cs @@ -201,7 +201,7 @@ public void can_set_timeout() { public void can_cancel_request() { var cts = new CancellationTokenSource(); var ex = Assert.ThrowsAsync(async () => { - var task = "https://httpbin.org/delay/5".GetAsync(cts.Token); + var task = "https://httpbin.org/delay/5".GetAsync(cancellationToken: cts.Token); cts.Cancel(); await task; }); @@ -215,7 +215,7 @@ public void can_set_timeout_and_cancellation_token() { var ex = Assert.ThrowsAsync(async () => { var task = "https://httpbin.org/delay/5" .WithTimeout(TimeSpan.FromMilliseconds(50)) - .GetAsync(cts.Token); + .GetAsync(cancellationToken: cts.Token); cts.Cancel(); await task; }); @@ -227,7 +227,7 @@ public void can_set_timeout_and_cancellation_token() { ex = Assert.ThrowsAsync(async () => { await "https://httpbin.org/delay/5" .WithTimeout(TimeSpan.FromMilliseconds(50)) - .GetAsync(cts.Token); + .GetAsync(cancellationToken: cts.Token); }); Assert.That(ex.InnerException is OperationCanceledException); Assert.IsFalse(cts.Token.IsCancellationRequested); diff --git a/src/Flurl.CodeGen/HttpExtensionMethod.cs b/src/Flurl.CodeGen/HttpExtensionMethod.cs index a6f97035..c1aaedc3 100644 --- a/src/Flurl.CodeGen/HttpExtensionMethod.cs +++ b/src/Flurl.CodeGen/HttpExtensionMethod.cs @@ -1,3 +1,5 @@ +using System; + namespace Flurl.CodeGen { public class HttpExtensionMethod : ExtensionMethod @@ -11,19 +13,21 @@ public HttpExtensionMethod(string verb, bool isGeneric, string reqBodyType, stri if (verb == null) AddArg("verb", "HttpMethod", "The HTTP verb used to make the request."); - if (HasRequestBody) { + if (HasRequestBody) { if (reqBodyType == "Json") - AddArg("data", "object", "An object representing the request body, which will be serialized to JSON."); + AddArg("body", "object", "An object representing the request body, which will be serialized to JSON."); + else if (reqBodyType == "UrlEncoded") + AddArg("body", "object", "An object representing the request body, which will be serialized to a URL-encoded string."); else if (reqBodyType == "String") - AddArg("data", "string", "Contents of the request body."); + AddArg("body", "string", "The request body."); else if (reqBodyType == null) - AddArg("content", "HttpContent", "Contents of the request body.", "null"); + AddArg("content", "HttpContent", "The request body content.", "null"); else - AddArg("data", "object", "Contents of the request body."); + throw new Exception("how did we get here?"); } - AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default(CancellationToken)"); AddArg("completionOption", "HttpCompletionOption", "The HttpCompletionOption used in the request. Optional.", "HttpCompletionOption.ResponseContentRead"); + AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default"); Returns($"Task<{TaskArg}>", $"A Task whose result is {ReturnTypeDescription}."); } diff --git a/src/Flurl.CodeGen/Metadata.cs b/src/Flurl.CodeGen/Metadata.cs index 2723da8c..70275295 100644 --- a/src/Flurl.CodeGen/Metadata.cs +++ b/src/Flurl.CodeGen/Metadata.cs @@ -131,13 +131,13 @@ public static IEnumerable GetRequestReturningExtensions(MethodA .AddArg("localFolderPath", "string", "Path of local folder where file is to be downloaded.") .AddArg("localFileName", "string", "Name of local file. If not specified, the source filename (last segment of the URL) is used.", "null") .AddArg("bufferSize", "int", "Buffer size in bytes. Default is 4096.", "4096") - .AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default(CancellationToken)"); + .AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default"); yield return new ExtensionMethod("PostMultipartAsync", "Creates a FlurlRequest and sends an asynchronous multipart/form-data POST request.") .Returns("Task", "A Task whose result is the received IFlurlResponse.") .Extends(extendedArg) .AddArg("buildContent", "Action", "A delegate for building the content parts.") - .AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default(CancellationToken)"); + .AddArg("cancellationToken", "CancellationToken", "The token to monitor for cancellation requests.", "default"); } /// diff --git a/src/Flurl.CodeGen/Program.cs b/src/Flurl.CodeGen/Program.cs index c964ea3b..f3fac5e8 100644 --- a/src/Flurl.CodeGen/Program.cs +++ b/src/Flurl.CodeGen/Program.cs @@ -118,16 +118,14 @@ private static void WriteHttpExtensionMethods(CodeWriter writer) { xm.HttpVerb == "Patch" ? "new HttpMethod(\"PATCH\")" : // there's no HttpMethod.Patch "HttpMethod." + xm.HttpVerb); - if (xm.HasRequestBody) - args.Add("content: content"); - - args.Add("cancellationToken: cancellationToken"); - args.Add("completionOption: completionOption"); + args.Add(xm.HasRequestBody ? "content" : "null"); + args.Add("completionOption"); + args.Add("cancellationToken"); if (xm.RequestBodyType != null) { writer.WriteLine("var content = new Captured@0Content(@1);", xm.RequestBodyType, - xm.RequestBodyType == "String" ? "data" : $"request.Settings.{xm.RequestBodyType}Serializer.Serialize(data)"); + xm.RequestBodyType == "String" ? "body" : $"request.Settings.{xm.RequestBodyType}Serializer.Serialize(body)"); } var receive = (xm.ResponseBodyType != null) ? $".Receive{xm.ResponseBodyType}{genericArg}()" : ""; diff --git a/src/Flurl.Http/Configuration/FlurlHttpSettings.cs b/src/Flurl.Http/Configuration/FlurlHttpSettings.cs index 49c80268..8693ae8a 100644 --- a/src/Flurl.Http/Configuration/FlurlHttpSettings.cs +++ b/src/Flurl.Http/Configuration/FlurlHttpSettings.cs @@ -158,7 +158,7 @@ internal T Get([CallerMemberName]string propName = null) { testVals?.ContainsKey(propName) == true ? (T)testVals[propName] : _vals.ContainsKey(propName) ? (T)_vals[propName] : Defaults != null ? (T)Defaults.Get(propName) : - default(T); + default; } /// diff --git a/src/Flurl.Http/DownloadExtensions.cs b/src/Flurl.Http/DownloadExtensions.cs index ace33bb5..b59e91d0 100644 --- a/src/Flurl.Http/DownloadExtensions.cs +++ b/src/Flurl.Http/DownloadExtensions.cs @@ -20,10 +20,9 @@ public static class DownloadExtensions /// Buffer size in bytes. Default is 4096. /// The token to monitor for cancellation requests. /// A Task whose result is the local path of the downloaded file. - public static async Task DownloadFileAsync(this IFlurlRequest request, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default(CancellationToken)) { - using (var resp = await request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false)) { - localFileName = - localFileName ?? + public static async Task DownloadFileAsync(this IFlurlRequest request, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default) { + using (var resp = await request.SendAsync(HttpMethod.Get, null, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false)) { + localFileName ??= GetFileNameFromHeaders(resp.ResponseMessage) ?? GetFileNameFromPath(request); diff --git a/src/Flurl.Http/FlurlRequest.cs b/src/Flurl.Http/FlurlRequest.cs index a340114c..04f10c26 100644 --- a/src/Flurl.Http/FlurlRequest.cs +++ b/src/Flurl.Http/FlurlRequest.cs @@ -51,7 +51,7 @@ public interface IFlurlRequest : IHttpSettingsContainer /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. /// A Task whose result is the received IFlurlResponse. - Task SendAsync(HttpMethod verb, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead); + Task SendAsync(HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default); } /// @@ -157,7 +157,7 @@ where c.ShouldSendTo(this.Url, out _) } /// - public async Task SendAsync(HttpMethod verb, HttpContent content = null, CancellationToken cancellationToken = default, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { + public async Task SendAsync(HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { _client = Client; // "freeze" the client at this point to avoid excessive calls to FlurlClientFactory.Get (#374) Verb = verb; @@ -186,7 +186,7 @@ public async Task SendAsync(HttpMethod verb, HttpContent content call.Response = new FlurlResponse(call.HttpResponseMessage, CookieJar); if (call.Succeeded) { - var redirResponse = await ProcessRedirectAsync(call, cancellationToken, completionOption).ConfigureAwait(false); + var redirResponse = await ProcessRedirectAsync(call, completionOption, cancellationToken).ConfigureAwait(false); return redirResponse ?? call.Response; } else @@ -231,7 +231,7 @@ private CancellationToken GetCancellationTokenWithTimeout(CancellationToken orig } } - private async Task ProcessRedirectAsync(FlurlCall call, CancellationToken cancellationToken, HttpCompletionOption completionOption) { + private async Task ProcessRedirectAsync(FlurlCall call, HttpCompletionOption completionOption, CancellationToken cancellationToken) { if (Settings.Redirects.Enabled) call.Redirect = GetRedirect(call); @@ -267,8 +267,8 @@ private async Task ProcessRedirectAsync(FlurlCall call, Cancella return await redir.SendAsync( changeToGet ? HttpMethod.Get : call.HttpRequestMessage.Method, changeToGet ? null : call.HttpRequestMessage.Content, - ct, - completionOption).ConfigureAwait(false); + completionOption, + ct).ConfigureAwait(false); } finally { cts?.Dispose(); diff --git a/src/Flurl.Http/GeneratedExtensions.cs b/src/Flurl.Http/GeneratedExtensions.cs index 94f56f7c..c7cb29fa 100644 --- a/src/Flurl.Http/GeneratedExtensions.cs +++ b/src/Flurl.Http/GeneratedExtensions.cs @@ -20,13 +20,13 @@ public static class GeneratedExtensions /// /// This IFlurlRequest /// The HTTP verb used to make the request. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendJsonAsync(this IFlurlRequest request, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(data)); - return request.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task SendJsonAsync(this IFlurlRequest request, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body)); + return request.SendAsync(verb, content, completionOption, cancellationToken); } /// @@ -34,13 +34,13 @@ public static class GeneratedExtensions /// /// This IFlurlRequest /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendStringAsync(this IFlurlRequest request, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedStringContent(data); - return request.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task SendStringAsync(this IFlurlRequest request, HttpMethod verb, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedStringContent(body); + return request.SendAsync(verb, content, completionOption, cancellationToken); } /// @@ -48,228 +48,228 @@ public static class GeneratedExtensions /// /// This IFlurlRequest /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendUrlEncodedAsync(this IFlurlRequest request, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(data)); - return request.SendAsync(verb, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task SendUrlEncodedAsync(this IFlurlRequest request, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(body)); + return request.SendAsync(verb, content, completionOption, cancellationToken); } /// /// Sends an asynchronous GET request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task GetAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task GetAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Get, null, completionOption, cancellationToken); } /// /// Sends an asynchronous GET request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the JSON response body deserialized to an object of type T. - public static Task GetJsonAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveJson(); + public static Task GetJsonAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Get, null, completionOption, cancellationToken).ReceiveJson(); } /// /// Sends an asynchronous GET request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a string. - public static Task GetStringAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveString(); + public static Task GetStringAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Get, null, completionOption, cancellationToken).ReceiveString(); } /// /// Sends an asynchronous GET request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a Stream. - public static Task GetStreamAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveStream(); + public static Task GetStreamAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Get, null, completionOption, cancellationToken).ReceiveStream(); } /// /// Sends an asynchronous GET request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a byte array. - public static Task GetBytesAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Get, cancellationToken: cancellationToken, completionOption: completionOption).ReceiveBytes(); + public static Task GetBytesAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Get, null, completionOption, cancellationToken).ReceiveBytes(); } /// /// Sends an asynchronous POST request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostAsync(this IFlurlRequest request, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PostAsync(this IFlurlRequest request, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken); } /// /// Sends an asynchronous POST request. /// /// This IFlurlRequest - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostJsonAsync(this IFlurlRequest request, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(data)); - return request.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PostJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body)); + return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken); } /// /// Sends an asynchronous POST request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostStringAsync(this IFlurlRequest request, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedStringContent(data); - return request.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PostStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedStringContent(body); + return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken); } /// /// Sends an asynchronous POST request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostUrlEncodedAsync(this IFlurlRequest request, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(data)); - return request.SendAsync(HttpMethod.Post, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PostUrlEncodedAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(body)); + return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken); } /// /// Sends an asynchronous HEAD request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task HeadAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Head, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task HeadAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Head, null, completionOption, cancellationToken); } /// /// Sends an asynchronous PUT request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutAsync(this IFlurlRequest request, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PutAsync(this IFlurlRequest request, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Put, content, completionOption, cancellationToken); } /// /// Sends an asynchronous PUT request. /// /// This IFlurlRequest - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutJsonAsync(this IFlurlRequest request, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(data)); - return request.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PutJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body)); + return request.SendAsync(HttpMethod.Put, content, completionOption, cancellationToken); } /// /// Sends an asynchronous PUT request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutStringAsync(this IFlurlRequest request, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedStringContent(data); - return request.SendAsync(HttpMethod.Put, content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PutStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedStringContent(body); + return request.SendAsync(HttpMethod.Put, content, completionOption, cancellationToken); } /// /// Sends an asynchronous DELETE request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task DeleteAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Delete, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task DeleteAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Delete, null, completionOption, cancellationToken); } /// /// Sends an asynchronous PATCH request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchAsync(this IFlurlRequest request, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PatchAsync(this IFlurlRequest request, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(new HttpMethod("PATCH"), content, completionOption, cancellationToken); } /// /// Sends an asynchronous PATCH request. /// /// This IFlurlRequest - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchJsonAsync(this IFlurlRequest request, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(data)); - return request.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PatchJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body)); + return request.SendAsync(new HttpMethod("PATCH"), content, completionOption, cancellationToken); } /// /// Sends an asynchronous PATCH request. /// /// This IFlurlRequest - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchStringAsync(this IFlurlRequest request, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - var content = new CapturedStringContent(data); - return request.SendAsync(new HttpMethod("PATCH"), content: content, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task PatchStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + var content = new CapturedStringContent(body); + return request.SendAsync(new HttpMethod("PATCH"), content, completionOption, cancellationToken); } /// /// Sends an asynchronous OPTIONS request. /// /// This IFlurlRequest - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task OptionsAsync(this IFlurlRequest request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return request.SendAsync(HttpMethod.Options, cancellationToken: cancellationToken, completionOption: completionOption); + public static Task OptionsAsync(this IFlurlRequest request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return request.SendAsync(HttpMethod.Options, null, completionOption, cancellationToken); } /// @@ -277,12 +277,12 @@ public static class GeneratedExtensions /// /// This Flurl.Url. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendAsync(this Url url, HttpMethod verb, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendAsync(verb, content, cancellationToken, completionOption); + public static Task SendAsync(this Url url, HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendAsync(verb, content, completionOption, cancellationToken); } /// @@ -290,12 +290,12 @@ public static class GeneratedExtensions /// /// This Flurl.Url. /// The HTTP verb used to make the request. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendJsonAsync(this Url url, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendJsonAsync(verb, data, cancellationToken, completionOption); + public static Task SendJsonAsync(this Url url, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendJsonAsync(verb, body, completionOption, cancellationToken); } /// @@ -303,12 +303,12 @@ public static class GeneratedExtensions /// /// This Flurl.Url. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendStringAsync(this Url url, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendStringAsync(verb, data, cancellationToken, completionOption); + public static Task SendStringAsync(this Url url, HttpMethod verb, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendStringAsync(verb, body, completionOption, cancellationToken); } /// @@ -316,220 +316,220 @@ public static class GeneratedExtensions /// /// This Flurl.Url. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendUrlEncodedAsync(this Url url, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendUrlEncodedAsync(verb, data, cancellationToken, completionOption); + public static Task SendUrlEncodedAsync(this Url url, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendUrlEncodedAsync(verb, body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task GetAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetAsync(cancellationToken, completionOption); + public static Task GetAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the JSON response body deserialized to an object of type T. - public static Task GetJsonAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetJsonAsync(cancellationToken, completionOption); + public static Task GetJsonAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetJsonAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a string. - public static Task GetStringAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetStringAsync(cancellationToken, completionOption); + public static Task GetStringAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetStringAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a Stream. - public static Task GetStreamAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetStreamAsync(cancellationToken, completionOption); + public static Task GetStreamAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetStreamAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a byte array. - public static Task GetBytesAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetBytesAsync(cancellationToken, completionOption); + public static Task GetBytesAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetBytesAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostAsync(this Url url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostAsync(content, cancellationToken, completionOption); + public static Task PostAsync(this Url url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This Flurl.Url. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostJsonAsync(this Url url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostJsonAsync(data, cancellationToken, completionOption); + public static Task PostJsonAsync(this Url url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostStringAsync(this Url url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostStringAsync(data, cancellationToken, completionOption); + public static Task PostStringAsync(this Url url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostUrlEncodedAsync(this Url url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostUrlEncodedAsync(data, cancellationToken, completionOption); + public static Task PostUrlEncodedAsync(this Url url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostUrlEncodedAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous HEAD request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task HeadAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).HeadAsync(cancellationToken, completionOption); + public static Task HeadAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).HeadAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutAsync(this Url url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutAsync(content, cancellationToken, completionOption); + public static Task PutAsync(this Url url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This Flurl.Url. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutJsonAsync(this Url url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutJsonAsync(data, cancellationToken, completionOption); + public static Task PutJsonAsync(this Url url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutStringAsync(this Url url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutStringAsync(data, cancellationToken, completionOption); + public static Task PutStringAsync(this Url url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous DELETE request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task DeleteAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).DeleteAsync(cancellationToken, completionOption); + public static Task DeleteAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).DeleteAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchAsync(this Url url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchAsync(content, cancellationToken, completionOption); + public static Task PatchAsync(this Url url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This Flurl.Url. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchJsonAsync(this Url url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchJsonAsync(data, cancellationToken, completionOption); + public static Task PatchJsonAsync(this Url url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This Flurl.Url. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchStringAsync(this Url url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchStringAsync(data, cancellationToken, completionOption); + public static Task PatchStringAsync(this Url url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous OPTIONS request. /// /// This Flurl.Url. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task OptionsAsync(this Url url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).OptionsAsync(cancellationToken, completionOption); + public static Task OptionsAsync(this Url url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).OptionsAsync(completionOption, cancellationToken); } /// @@ -704,7 +704,7 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// Buffer size in bytes. Default is 4096. /// The token to monitor for cancellation requests. /// A Task whose result is the local path of the downloaded file. - public static Task DownloadFileAsync(this Url url, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task DownloadFileAsync(this Url url, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default) { return new FlurlRequest(url).DownloadFileAsync(localFolderPath, localFileName, bufferSize, cancellationToken); } @@ -715,7 +715,7 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// A delegate for building the content parts. /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostMultipartAsync(this Url url, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task PostMultipartAsync(this Url url, Action buildContent, CancellationToken cancellationToken = default) { return new FlurlRequest(url).PostMultipartAsync(buildContent, cancellationToken); } @@ -724,12 +724,12 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// /// This URL. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendAsync(this string url, HttpMethod verb, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendAsync(verb, content, cancellationToken, completionOption); + public static Task SendAsync(this string url, HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendAsync(verb, content, completionOption, cancellationToken); } /// @@ -737,12 +737,12 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// /// This URL. /// The HTTP verb used to make the request. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendJsonAsync(this string url, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendJsonAsync(verb, data, cancellationToken, completionOption); + public static Task SendJsonAsync(this string url, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendJsonAsync(verb, body, completionOption, cancellationToken); } /// @@ -750,12 +750,12 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// /// This URL. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendStringAsync(this string url, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendStringAsync(verb, data, cancellationToken, completionOption); + public static Task SendStringAsync(this string url, HttpMethod verb, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendStringAsync(verb, body, completionOption, cancellationToken); } /// @@ -763,220 +763,220 @@ public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { /// /// This URL. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendUrlEncodedAsync(this string url, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).SendUrlEncodedAsync(verb, data, cancellationToken, completionOption); + public static Task SendUrlEncodedAsync(this string url, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).SendUrlEncodedAsync(verb, body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task GetAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetAsync(cancellationToken, completionOption); + public static Task GetAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the JSON response body deserialized to an object of type T. - public static Task GetJsonAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetJsonAsync(cancellationToken, completionOption); + public static Task GetJsonAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetJsonAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a string. - public static Task GetStringAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetStringAsync(cancellationToken, completionOption); + public static Task GetStringAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetStringAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a Stream. - public static Task GetStreamAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetStreamAsync(cancellationToken, completionOption); + public static Task GetStreamAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetStreamAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a byte array. - public static Task GetBytesAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).GetBytesAsync(cancellationToken, completionOption); + public static Task GetBytesAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).GetBytesAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostAsync(this string url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostAsync(content, cancellationToken, completionOption); + public static Task PostAsync(this string url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This URL. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostJsonAsync(this string url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostJsonAsync(data, cancellationToken, completionOption); + public static Task PostJsonAsync(this string url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostStringAsync(this string url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostStringAsync(data, cancellationToken, completionOption); + public static Task PostStringAsync(this string url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostUrlEncodedAsync(this string url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PostUrlEncodedAsync(data, cancellationToken, completionOption); + public static Task PostUrlEncodedAsync(this string url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PostUrlEncodedAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous HEAD request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task HeadAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).HeadAsync(cancellationToken, completionOption); + public static Task HeadAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).HeadAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutAsync(this string url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutAsync(content, cancellationToken, completionOption); + public static Task PutAsync(this string url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This URL. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutJsonAsync(this string url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutJsonAsync(data, cancellationToken, completionOption); + public static Task PutJsonAsync(this string url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutStringAsync(this string url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PutStringAsync(data, cancellationToken, completionOption); + public static Task PutStringAsync(this string url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PutStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous DELETE request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task DeleteAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).DeleteAsync(cancellationToken, completionOption); + public static Task DeleteAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).DeleteAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchAsync(this string url, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchAsync(content, cancellationToken, completionOption); + public static Task PatchAsync(this string url, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This URL. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchJsonAsync(this string url, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchJsonAsync(data, cancellationToken, completionOption); + public static Task PatchJsonAsync(this string url, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This URL. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchStringAsync(this string url, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).PatchStringAsync(data, cancellationToken, completionOption); + public static Task PatchStringAsync(this string url, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).PatchStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous OPTIONS request. /// /// This URL. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task OptionsAsync(this string url, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(url).OptionsAsync(cancellationToken, completionOption); + public static Task OptionsAsync(this string url, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(url).OptionsAsync(completionOption, cancellationToken); } /// @@ -1151,7 +1151,7 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// Buffer size in bytes. Default is 4096. /// The token to monitor for cancellation requests. /// A Task whose result is the local path of the downloaded file. - public static Task DownloadFileAsync(this string url, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task DownloadFileAsync(this string url, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default) { return new FlurlRequest(url).DownloadFileAsync(localFolderPath, localFileName, bufferSize, cancellationToken); } @@ -1162,7 +1162,7 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// A delegate for building the content parts. /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostMultipartAsync(this string url, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task PostMultipartAsync(this string url, Action buildContent, CancellationToken cancellationToken = default) { return new FlurlRequest(url).PostMultipartAsync(buildContent, cancellationToken); } @@ -1171,12 +1171,12 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// /// This System.Uri. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendAsync(this Uri uri, HttpMethod verb, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).SendAsync(verb, content, cancellationToken, completionOption); + public static Task SendAsync(this Uri uri, HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).SendAsync(verb, content, completionOption, cancellationToken); } /// @@ -1184,12 +1184,12 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// /// This System.Uri. /// The HTTP verb used to make the request. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendJsonAsync(this Uri uri, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).SendJsonAsync(verb, data, cancellationToken, completionOption); + public static Task SendJsonAsync(this Uri uri, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).SendJsonAsync(verb, body, completionOption, cancellationToken); } /// @@ -1197,12 +1197,12 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// /// This System.Uri. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendStringAsync(this Uri uri, HttpMethod verb, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).SendStringAsync(verb, data, cancellationToken, completionOption); + public static Task SendStringAsync(this Uri uri, HttpMethod verb, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).SendStringAsync(verb, body, completionOption, cancellationToken); } /// @@ -1210,220 +1210,220 @@ public static IFlurlRequest WithClient(this string url, IFlurlClient client) { /// /// This System.Uri. /// The HTTP verb used to make the request. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task SendUrlEncodedAsync(this Uri uri, HttpMethod verb, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).SendUrlEncodedAsync(verb, data, cancellationToken, completionOption); + public static Task SendUrlEncodedAsync(this Uri uri, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).SendUrlEncodedAsync(verb, body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task GetAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).GetAsync(cancellationToken, completionOption); + public static Task GetAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).GetAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the JSON response body deserialized to an object of type T. - public static Task GetJsonAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).GetJsonAsync(cancellationToken, completionOption); + public static Task GetJsonAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).GetJsonAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a string. - public static Task GetStringAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).GetStringAsync(cancellationToken, completionOption); + public static Task GetStringAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).GetStringAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a Stream. - public static Task GetStreamAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).GetStreamAsync(cancellationToken, completionOption); + public static Task GetStreamAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).GetStreamAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous GET request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the response body as a byte array. - public static Task GetBytesAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).GetBytesAsync(cancellationToken, completionOption); + public static Task GetBytesAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).GetBytesAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostAsync(this Uri uri, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PostAsync(content, cancellationToken, completionOption); + public static Task PostAsync(this Uri uri, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PostAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This System.Uri. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostJsonAsync(this Uri uri, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PostJsonAsync(data, cancellationToken, completionOption); + public static Task PostJsonAsync(this Uri uri, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PostJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostStringAsync(this Uri uri, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PostStringAsync(data, cancellationToken, completionOption); + public static Task PostStringAsync(this Uri uri, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PostStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous POST request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to a URL-encoded string. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostUrlEncodedAsync(this Uri uri, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PostUrlEncodedAsync(data, cancellationToken, completionOption); + public static Task PostUrlEncodedAsync(this Uri uri, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PostUrlEncodedAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous HEAD request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task HeadAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).HeadAsync(cancellationToken, completionOption); + public static Task HeadAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).HeadAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutAsync(this Uri uri, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PutAsync(content, cancellationToken, completionOption); + public static Task PutAsync(this Uri uri, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PutAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This System.Uri. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutJsonAsync(this Uri uri, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PutJsonAsync(data, cancellationToken, completionOption); + public static Task PutJsonAsync(this Uri uri, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PutJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PUT request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PutStringAsync(this Uri uri, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PutStringAsync(data, cancellationToken, completionOption); + public static Task PutStringAsync(this Uri uri, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PutStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous DELETE request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task DeleteAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).DeleteAsync(cancellationToken, completionOption); + public static Task DeleteAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).DeleteAsync(completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body content. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchAsync(this Uri uri, HttpContent content = null, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PatchAsync(content, cancellationToken, completionOption); + public static Task PatchAsync(this Uri uri, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PatchAsync(content, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This System.Uri. - /// An object representing the request body, which will be serialized to JSON. - /// The token to monitor for cancellation requests. + /// An object representing the request body, which will be serialized to JSON. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchJsonAsync(this Uri uri, object data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PatchJsonAsync(data, cancellationToken, completionOption); + public static Task PatchJsonAsync(this Uri uri, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PatchJsonAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous PATCH request. /// /// This System.Uri. - /// Contents of the request body. - /// The token to monitor for cancellation requests. + /// The request body. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PatchStringAsync(this Uri uri, string data, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).PatchStringAsync(data, cancellationToken, completionOption); + public static Task PatchStringAsync(this Uri uri, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).PatchStringAsync(body, completionOption, cancellationToken); } /// /// Creates a FlurlRequest and sends an asynchronous OPTIONS request. /// /// This System.Uri. - /// The token to monitor for cancellation requests. /// The HttpCompletionOption used in the request. Optional. + /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task OptionsAsync(this Uri uri, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { - return new FlurlRequest(uri).OptionsAsync(cancellationToken, completionOption); + public static Task OptionsAsync(this Uri uri, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) { + return new FlurlRequest(uri).OptionsAsync(completionOption, cancellationToken); } /// @@ -1598,7 +1598,7 @@ public static IFlurlRequest WithClient(this Uri uri, IFlurlClient client) { /// Buffer size in bytes. Default is 4096. /// The token to monitor for cancellation requests. /// A Task whose result is the local path of the downloaded file. - public static Task DownloadFileAsync(this Uri uri, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task DownloadFileAsync(this Uri uri, string localFolderPath, string localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default) { return new FlurlRequest(uri).DownloadFileAsync(localFolderPath, localFileName, bufferSize, cancellationToken); } @@ -1609,7 +1609,7 @@ public static IFlurlRequest WithClient(this Uri uri, IFlurlClient client) { /// A delegate for building the content parts. /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostMultipartAsync(this Uri uri, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task PostMultipartAsync(this Uri uri, Action buildContent, CancellationToken cancellationToken = default) { return new FlurlRequest(uri).PostMultipartAsync(buildContent, cancellationToken); } diff --git a/src/Flurl.Http/MultipartExtensions.cs b/src/Flurl.Http/MultipartExtensions.cs index 2e3f3e82..89be9453 100644 --- a/src/Flurl.Http/MultipartExtensions.cs +++ b/src/Flurl.Http/MultipartExtensions.cs @@ -18,10 +18,10 @@ public static class MultipartExtensions /// The IFlurlRequest. /// The token to monitor for cancellation requests. /// A Task whose result is the received IFlurlResponse. - public static Task PostMultipartAsync(this IFlurlRequest request, Action buildContent, CancellationToken cancellationToken = default(CancellationToken)) { + public static Task PostMultipartAsync(this IFlurlRequest request, Action buildContent, CancellationToken cancellationToken = default) { var cmc = new CapturedMultipartContent(request.Settings); buildContent(cmc); - return request.SendAsync(HttpMethod.Post, cmc, cancellationToken); + return request.SendAsync(HttpMethod.Post, cmc, HttpCompletionOption.ResponseContentRead, cancellationToken); } } } diff --git a/src/Flurl.Http/ResponseExtensions.cs b/src/Flurl.Http/ResponseExtensions.cs index 046dcfda..8103f75b 100644 --- a/src/Flurl.Http/ResponseExtensions.cs +++ b/src/Flurl.Http/ResponseExtensions.cs @@ -19,7 +19,7 @@ public static class ResponseExtensions /// Condition. public static async Task ReceiveJson(this Task response) { using (var resp = await response.ConfigureAwait(false)) { - if (resp == null) return default(T); + if (resp == null) return default; return await resp.GetJsonAsync().ConfigureAwait(false); } }