diff --git a/src/Cake.Curl.Tests/CurlDownloadFileTests.cs b/src/Cake.Curl.Tests/CurlDownloadFileTests.cs index 83ff3bd..24bebc4 100644 --- a/src/Cake.Curl.Tests/CurlDownloadFileTests.cs +++ b/src/Cake.Curl.Tests/CurlDownloadFileTests.cs @@ -277,6 +277,38 @@ public void Should_Set_The_Request_Command_In_Quotes_And_Upper_Case_As_Argument( // Then Assert.Contains("--request \"COMMAND\"", result.Args); } + + [Fact] + public void Should_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlDownloadFileFixture + { + Settings = { FollowRedirects = true } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.Contains("--location", result.Args); + } + + [Fact] + public void Should_Not_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlDownloadFileFixture + { + Settings = { FollowRedirects = false } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.DoesNotContain("--location", result.Args); + } } } } diff --git a/src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs b/src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs index 099381e..df5a8e3 100644 --- a/src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs +++ b/src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs @@ -309,6 +309,38 @@ public void Should_Set_The_Request_Command_In_Quotes_And_Upper_Case_As_Argument( // Then Assert.Contains("--request \"COMMAND\"", result.Args); } + + [Fact] + public void Should_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlDownloadMultipleFilesFixture + { + Settings = { FollowRedirects = true } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.Contains("--location", result.Args); + } + + [Fact] + public void Should_Not_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlDownloadFileFixture + { + Settings = { FollowRedirects = false } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.DoesNotContain("--location", result.Args); + } } } } diff --git a/src/Cake.Curl.Tests/CurlUploadFileTests.cs b/src/Cake.Curl.Tests/CurlUploadFileTests.cs index af3f248..f8144bb 100644 --- a/src/Cake.Curl.Tests/CurlUploadFileTests.cs +++ b/src/Cake.Curl.Tests/CurlUploadFileTests.cs @@ -285,6 +285,38 @@ public void Should_Set_The_Request_Command_In_Quotes_And_Upper_Case_As_Argument( // Then Assert.Contains("--request \"COMMAND\"", result.Args); } + + [Fact] + public void Should_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlUploadFileFixture + { + Settings = { FollowRedirects = true } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.Contains("--location", result.Args); + } + + [Fact] + public void Should_Not_Set_The_Location_Option_As_Argument() + { + // Given + var fixture = new CurlDownloadFileFixture + { + Settings = { FollowRedirects = false } + }; + + // When + var result = fixture.Run(); + + // Then + Assert.DoesNotContain("--location", result.Args); + } } } } diff --git a/src/Cake.Curl/ArgumentsExtensions.cs b/src/Cake.Curl/ArgumentsExtensions.cs index f741133..3d12ebd 100644 --- a/src/Cake.Curl/ArgumentsExtensions.cs +++ b/src/Cake.Curl/ArgumentsExtensions.cs @@ -42,6 +42,11 @@ internal static void AppendSettings( "--request", settings.RequestCommand.ToUpperInvariant()); } + + if (settings.FollowRedirects) + { + arguments.Append("--location"); + } } } } diff --git a/src/Cake.Curl/CurlSettings.cs b/src/Cake.Curl/CurlSettings.cs index 937b271..397ba24 100644 --- a/src/Cake.Curl/CurlSettings.cs +++ b/src/Cake.Curl/CurlSettings.cs @@ -62,5 +62,21 @@ public class CurlSettings : ToolSettings /// is a far better choice. /// public string RequestCommand { get; set; } + + /// + /// Gets or sets a flag telling curl to follow HTTP redirects. + /// + /// + /// If the remote service responds with a 3xx status code and this flag + /// is set to , curl will redo the request + /// to the URL found in the Location response header. + /// Note that if the remote service responded with a 301 (Moved Permanently), + /// 302 (Found) or 303 (See Other) status code, + /// curl will redo the request using the GET method, even if the original request + /// was using another method (like for example PUT or POST). + /// For all other 3xx status codes, curl will redo the request using the same method + /// as the one specified in the original request. + /// + public bool FollowRedirects { get; set; } } }