Skip to content

Commit

Permalink
Merge pull request #2625 from stripe/richardm-stop-mutation
Browse files Browse the repository at this point in the history
Stop `FileService` from mutating its `RequestOptions` argument
  • Loading branch information
richardm-stripe committed Dec 21, 2022
2 parents 57e9822 + 450d2e9 commit 84932a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Stripe.net/Services/Files/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private RequestOptions SetupRequestOptionsForFilesRequest(RequestOptions request

if (requestOptions.BaseUrl == null)
{
requestOptions = requestOptions.Clone();
requestOptions.BaseUrl = this.Client.FilesBase;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Stripe.net/Services/_common/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ public class RequestOptions
/// is only used for creating ephemeral keys, which require a specific API version.
/// </remarks>
internal string StripeVersion { get; set; }

internal RequestOptions Clone()
{
return (RequestOptions)this.MemberwiseClone();
}
}
}
5 changes: 4 additions & 1 deletion src/StripeTests/Services/Files/FileServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ public class FileServiceTest : BaseStripeTest
[Fact]
public void Create()
{
var file = this.service.Create(this.createOptions);
var requestOptions = new RequestOptions();

var file = this.service.Create(this.createOptions, requestOptions);
this.AssertRequest(HttpMethod.Post, "/v1/files");
Assert.Null(requestOptions.BaseUrl);
Assert.NotNull(file);
Assert.Equal("file", file.Object);
}
Expand Down

0 comments on commit 84932a8

Please sign in to comment.