Skip to content

Commit

Permalink
Adds support for the location option (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Jan 16, 2018
1 parent 0e84a47 commit 0d16203
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlDownloadFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlDownloadMultipleFilesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
32 changes: 32 additions & 0 deletions src/Cake.Curl.Tests/CurlUploadFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
5 changes: 5 additions & 0 deletions src/Cake.Curl/ArgumentsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ internal static void AppendSettings(
"--request",
settings.RequestCommand.ToUpperInvariant());
}

if (settings.FollowRedirects)
{
arguments.Append("--location");
}
}
}
}
16 changes: 16 additions & 0 deletions src/Cake.Curl/CurlSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,21 @@ public class CurlSettings : ToolSettings
/// is a far better choice.
/// </remarks>
public string RequestCommand { get; set; }

/// <summary>
/// Gets or sets a flag telling curl to follow HTTP redirects.
/// </summary>
/// <remarks>
/// If the remote service responds with a 3xx status code and this flag
/// is set to <see langword="true"/>, curl will redo the request
/// to the URL found in the <code>Location</code> response header.
/// Note that if the remote service responded with a <code>301</code> (<em>Moved Permanently</em>),
/// <code>302</code> (<em>Found</em>) or <code>303</code> (<em>See Other</em>) status code,
/// curl will redo the request using the <code>GET</code> method, even if the original request
/// was using another method (like for example <code>PUT</code> or <code>POST</code>).
/// For all other 3xx status codes, curl will redo the request using the same method
/// as the one specified in the original request.
/// </remarks>
public bool FollowRedirects { get; set; }
}
}

0 comments on commit 0d16203

Please sign in to comment.