Skip to content

Commit

Permalink
Do not modify the Timeout after instantiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Theken committed Sep 21, 2018
1 parent b4e29b3 commit cb7a945
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Postmark.Tests/ClientMessageClickQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClientMessageClickQueryTests : ClientBaseFixture
{
protected override void Setup()
{
_client = new PostmarkClient(READ_LINK_TRACKING_TEST_SERVER_TOKEN, requestTimeoutInSeconds: 60);
_client = new PostmarkClient(READ_LINK_TRACKING_TEST_SERVER_TOKEN);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Postmark.Tests/ClientMessageOpenQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClientMessageOpenQueryTests : ClientBaseFixture
{
protected override void Setup()
{
_client = new PostmarkClient(READ_SELENIUM_OPEN_TRACKING_TOKEN, requestTimeoutInSeconds: 60);
_client = new PostmarkClient(READ_SELENIUM_OPEN_TRACKING_TOKEN);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Postmark.Tests/ClientMessageSearchingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ClientMessageSearchingTests : ClientBaseFixture
{
protected override void Setup()
{
_client = new PostmarkClient(READ_SELENIUM_TEST_SERVER_TOKEN, requestTimeoutInSeconds: 60);
_client = new PostmarkClient(READ_SELENIUM_TEST_SERVER_TOKEN);
}

[Fact]
Expand Down
2 changes: 0 additions & 2 deletions src/Postmark/ISimpleHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace PostmarkDotNet
{
public interface ISimpleHttpClient
{
TimeSpan Timeout { get; set; }

Task<HttpResponseMessage> SendAsync(HttpRequestMessage request);
}
}
5 changes: 2 additions & 3 deletions src/Postmark/PostmarkAdminClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public class PostmarkAdminClient : PostmarkDotNet.PostmarkClientBase
/// Construct a PostmarkAdminClient.
/// </summary>
/// <param name="accountToken">The "accountToken" can be found by logging into your Postmark and navigating to https://postmarkapp.com/account/edit - Keep this token secret and safe.</param>
/// <param name="requestTimeoutInSeconds">The number of seconds to wait for the API to return before throwing a timeout exception.</param>
/// <param name="apiBaseUri">Optionally override the base url to the API. For example, you may fallback to HTTP (non-SSL) if your app requires it, though, this is not recommended.</param>
public PostmarkAdminClient(string accountToken, int requestTimeoutInSeconds = 30, string apiBaseUri = "https://api.postmarkapp.com")
: base(apiBaseUri, requestTimeoutInSeconds)
public PostmarkAdminClient(string accountToken, string apiBaseUri = "https://api.postmarkapp.com")
: base(apiBaseUri)
{
_authToken = accountToken;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Postmark/PostmarkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ protected override string AuthHeaderName
/// Instantiate the client.
/// </summary>
/// <param name="apiBaseUri">The base uri to use when connecting to Postmark. You should rarely need to modify this, except if you want to disable TLS (not recommended), or you are using a proxy of some sort to connect to the API.</param>
/// <param name="requestTimeoutInSeconds">The length of time to wait for an API request to complete. In most cases, this should not be modified. If your requests are timing out (for example, large batch submissions, you should consider reducing the size or number of messages you are submitting at one time before increasing this value).</param>
/// <param name="serverToken">Used for requests that require server level privileges. This token can be found on the Credentials tab under your Postmark server.</param>
public PostmarkClient(string serverToken, string apiBaseUri = "https://api.postmarkapp.com", int requestTimeoutInSeconds = 30)
: base(apiBaseUri, requestTimeoutInSeconds)
public PostmarkClient(string serverToken, string apiBaseUri = "https://api.postmarkapp.com")
: base(apiBaseUri)
{
_authToken = serverToken;
}
Expand Down
6 changes: 1 addition & 5 deletions src/Postmark/PostmarkClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ public abstract class PostmarkClientBase
/// </summary>
/// <param name="apiBaseUri"></param>
/// <param name="requestTimeoutInSeconds"></param>
public PostmarkClientBase(string apiBaseUri = "https://api.postmarkapp.com", int requestTimeoutInSeconds = 30)
public PostmarkClientBase(string apiBaseUri = "https://api.postmarkapp.com")
{
baseUri = new Uri(apiBaseUri);
_requestTimeout = requestTimeoutInSeconds;
}

protected abstract string AuthHeaderName { get; }

protected string _authToken;
private int _requestTimeout;

/// <summary>
/// The core delivery method for all other API methods.
Expand Down Expand Up @@ -81,8 +79,6 @@ protected async Task<TResponse> ProcessRequestAsync<TRequestBody, TResponse>(str
request.Headers.Add(AuthHeaderName, _authToken);
request.Headers.Add("User-Agent", _agent);

client.Timeout = TimeSpan.FromSeconds(this._requestTimeout);

var result = await client.SendAsync(request);

var body = await result.Content.ReadAsStringAsync();
Expand Down
12 changes: 2 additions & 10 deletions src/Postmark/SimpleHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ internal class SimpleHttpClient : ISimpleHttpClient
{
private HttpClient _client = new HttpClient();

public TimeSpan Timeout
{
get
{
return _client.Timeout;
}
set
{
_client.Timeout = value;
}
public SimpleHttpClient(TimeSpan? timeoutLength = null){
_client.Timeout = timeoutLength ?? TimeSpan.FromSeconds(30);
}

public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
Expand Down

0 comments on commit cb7a945

Please sign in to comment.