Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override Task<T> RequestAsync<T>(
if (baseAddress != BaseAddress.Api)
{
requestOptions ??= new RequestOptions();
requestOptions.BaseUrl = this.GetBaseUrl(baseAddress);
requestOptions.InternalBaseUrl = this.GetBaseUrl(baseAddress);
}

return this.client.RequestAsync<T>(method, path, options, requestOptions, cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion src/Stripe.net/Infrastructure/Public/LiveApiRequestor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private StripeRequest MakeStripeRequest(
}

var uri = StripeRequest.BuildUri(
requestOptions?.BaseUrl ?? this.GetBaseUrl(baseAddress),
requestOptions?.InternalBaseUrl ?? this.GetBaseUrl(baseAddress),
method,
path,
options,
Expand Down
7 changes: 7 additions & 0 deletions src/Stripe.net/Services/_common/RawRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ namespace Stripe

public class RawRequestOptions : RequestOptions
{
/// <summary>Gets or sets the base URL for the raw request.</summary>
/// <remarks>
/// Use this to send API calls to e.g. files.stripe.com or
/// a proxy address.
/// </remarks>
public string BaseUrl { get => this.InternalBaseUrl; set => this.InternalBaseUrl = value; }

/// <summary>Gets or sets additional headers for the request.</summary>
public Dictionary<string, string> AdditionalHeaders { get; set; } = new Dictionary<string, string>();

Expand Down
4 changes: 2 additions & 2 deletions src/Stripe.net/Services/_common/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class RequestOptions
/// <summary>Gets or sets the value or Stripe-Context request header.</summary>
public string StripeContext { get; set; }

/// <summary>Gets or sets the base URL for the request.</summary>
/// <summary>Gets the base URL for the request.</summary>
/// <remarks>
/// This is an internal property. It is set by services or individual request methods when
/// they need to send a request to a non-standard destination, e.g. <c>files.stripe.com</c>
/// for file creation requests or <c>connect.stripe.com</c> for OAuth requests.
/// </remarks>
internal string BaseUrl { get; set; }
internal string InternalBaseUrl { get; set; }

/// <summary>Gets or sets the API version for the request.</summary>
/// <remarks>
Expand Down
36 changes: 36 additions & 0 deletions src/StripeTests/Infrastructure/Public/StripeClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ public async Task RawRequestAsync_Json()
Assert.Equal("mes_123", obj.Id);
}

[Fact]
public async Task RawRequest_BaseUrl()
{
// Stub a request as stripe-mock does not support v2
this.MockHttpClientFixture.StubRequest(
HttpMethod.Post,
"/v2/billing/meter_event_session",
System.Net.HttpStatusCode.OK,
"{\"id\": \"mes_123\",\"object\":\"v2.billing.meter_event_session\"}");

var expectedBaseUrl = "https://test.stripetest.com";
var rawResponse = await this.stripeClient.RawRequestAsync(
HttpMethod.Post,
"/v2/billing/meter_event_session",
"{}",
new RawRequestOptions
{
BaseUrl = expectedBaseUrl,
AdditionalHeaders =
{
{ "foo", "bar" },
},
});

this.MockHttpClientFixture.MockHandler.Protected()
.Verify(
"SendAsync",
Times.Once(),
ItExpr.Is<HttpRequestMessage>(m =>
new Uri(expectedBaseUrl).Host == (string)m.Properties["OriginalHost"]),
ItExpr.IsAny<CancellationToken>());

var obj = this.stripeClient.Deserialize<Stripe.V2.Billing.MeterEventSession>(rawResponse.Content);
Assert.Equal("mes_123", obj.Id);
}

[Fact]
public async Task RawRequestAsyncIncludesCorrectUsage()
{
Expand Down
Loading