Skip to content

Commit

Permalink
Multiple issues fixed, see details (#170)
Browse files Browse the repository at this point in the history
* CancellationToken support (#166)
Timeout configuration support (#168)
Fixed project files for VS2017 RC as noted here: https://aka.ms/sdkimplicititems (#169)

* Make DefaultTimeout an auto-property

* Fixed project files broken by merge.
It appears the merge removed the includes, but did not remove the added Ignore property, thus no files (or few files depending on the project) were loaded causing compilation to fail.

* Constructor change as requested by @jterry75
  • Loading branch information
jasoncouture authored and jterry75 committed Feb 22, 2017
1 parent 4d990ee commit 9d156d1
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 196 deletions.
2 changes: 1 addition & 1 deletion src/Docker.DotNet.X509/Docker.DotNet.X509.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Docker.DotNet.X509</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion src/Docker.DotNet/Docker.DotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>Docker.DotNet</PackageId>
Expand Down
15 changes: 8 additions & 7 deletions src/Docker.DotNet/DockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public sealed class DockerClient : IDockerClient

public ISwarmOperations Swarm { get; }

public TimeSpan DefaultTimeout { get; set; }

private readonly HttpClient _client;
private readonly TimeSpan _defaultTimeout;

private readonly Uri _endpointBaseUri;

Expand Down Expand Up @@ -133,15 +134,15 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
_endpointBaseUri = uri;

_client = new HttpClient(Configuration.Credentials.GetHandler(handler), true);
_defaultTimeout = _client.Timeout;
DefaultTimeout = Configuration.DefaultTimeout;
_client.Timeout = s_InfiniteTimeout;
}

#region Convenience methods

internal Task<DockerApiResponse> MakeRequestAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, HttpMethod method, string path, IQueryString queryString)
internal Task<DockerApiResponse> MakeRequestAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, HttpMethod method, string path, IQueryString queryString, CancellationToken cancellationToken = default(CancellationToken))
{
return MakeRequestAsync(errorHandlers, method, path, queryString, null, null, CancellationToken.None);
return MakeRequestAsync(errorHandlers, method, path, queryString, cancellationToken);
}

internal Task<DockerApiResponse> MakeRequestAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, HttpMethod method, string path, IQueryString queryString, IRequestContent data)
Expand All @@ -163,9 +164,9 @@ internal Task<DockerApiStreamedResponse> MakeRequestForStreamedResponseAsync(IEn

#region HTTP Calls

internal async Task<DockerApiResponse> MakeRequestAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, HttpMethod method, string path, IQueryString queryString, IDictionary<string, string> headers, IRequestContent data)
internal async Task<DockerApiResponse> MakeRequestAsync(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, HttpMethod method, string path, IQueryString queryString, IDictionary<string, string> headers, IRequestContent data, CancellationToken cancellationToken = default(CancellationToken))
{
var response = await MakeRequestInnerAsync(null, HttpCompletionOption.ResponseContentRead, method, path, queryString, headers, data, default(CancellationToken)).ConfigureAwait(false);
var response = await MakeRequestInnerAsync(null, HttpCompletionOption.ResponseContentRead, method, path, queryString, headers, data, cancellationToken).ConfigureAwait(false);

var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Expand Down Expand Up @@ -232,7 +233,7 @@ private Task<HttpResponseMessage> MakeRequestInnerAsync(TimeSpan? requestTimeout
}
else
{
cancellationToken = CreateTimeoutToken(cancellationToken, _defaultTimeout);
cancellationToken = CreateTimeoutToken(cancellationToken, DefaultTimeout);
}

return _client.SendAsync(request, completionOption, cancellationToken);
Expand Down
20 changes: 13 additions & 7 deletions src/Docker.DotNet/DockerClientConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;

namespace Docker.DotNet
{
Expand All @@ -8,20 +9,25 @@ public class DockerClientConfiguration : IDisposable

public Credentials Credentials { get; internal set; }

public DockerClientConfiguration(Uri endpoint)
: this(endpoint, null)
{
}
public TimeSpan DefaultTimeout { get; internal set; } = TimeSpan.FromSeconds(100);

public DockerClientConfiguration(Uri endpoint, Credentials credentials)
public DockerClientConfiguration(Uri endpoint, Credentials credentials = null,
TimeSpan defaultTimeout = default(TimeSpan))
{
if (endpoint == null)
{
throw new ArgumentNullException(nameof(endpoint));
}


Credentials = credentials ?? new AnonymousCredentials();
EndpointBaseUri = endpoint;
if (defaultTimeout != TimeSpan.Zero)
{
if (defaultTimeout < Timeout.InfiniteTimeSpan)
// TODO: Should be a resource for localization.
// TODO: Is this a good message?
throw new ArgumentException("Timeout must be greater than Timeout.Infinite", nameof(defaultTimeout));
DefaultTimeout = defaultTimeout;
}
}

public DockerClient CreateClient()
Expand Down
Loading

0 comments on commit 9d156d1

Please sign in to comment.