Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HttpClient consistently across async and sync clients #566

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ private void SignBinaries(string path)

Sign(files, new SignToolSignSettings {
ToolPath = MakeAbsolute(File("./certificates/signtool.exe")),
TimeStampUri = new Uri("http://timestamp.globalsign.com/scripts/timestamp.dll"),
TimeStampUri = new Uri("http://rfc3161timestamp.globalsign.com/advanced"),
TimeStampDigestAlgorithm = SignToolDigestAlgorithm.Sha256,
CertPath = signingCertificatePath,
Password = signingCertificatePassword
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Octopus.Client
Octopus.Client.IOctopusClient
IDisposable
{
event Action<WebResponse> AfterReceivingHttpResponse
event Action<WebRequest> BeforeSendingHttpRequest
event Action<HttpResponseMessage> AfterReceivingHttpResponse
event Action<HttpRequestMessage> BeforeSendingHttpRequest
}
interface ILinkResolver
{
Expand Down Expand Up @@ -373,8 +373,8 @@ Octopus.Client
Octopus.Client.IOctopusClient
IDisposable
{
event Action<WebResponse> AfterReceivingHttpResponse
event Action<WebRequest> BeforeSendingHttpRequest
event Action<HttpResponseMessage> AfterReceivingHttpResponse
event Action<HttpRequestMessage> BeforeSendingHttpRequest
event Action<OctopusResponse> ReceivedOctopusResponse
event Action<OctopusRequest> SendingOctopusRequest
.ctor(Octopus.Client.OctopusServerEndpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Octopus.Client
Octopus.Client.IOctopusClient
IDisposable
{
event Action<WebResponse> AfterReceivingHttpResponse
event Action<WebRequest> BeforeSendingHttpRequest
event Action<HttpResponseMessage> AfterReceivingHttpResponse
event Action<HttpRequestMessage> BeforeSendingHttpRequest
}
interface ILinkResolver
{
Expand Down Expand Up @@ -373,8 +373,8 @@ Octopus.Client
Octopus.Client.IOctopusClient
IDisposable
{
event Action<WebResponse> AfterReceivingHttpResponse
event Action<WebRequest> BeforeSendingHttpRequest
event Action<HttpResponseMessage> AfterReceivingHttpResponse
event Action<HttpRequestMessage> BeforeSendingHttpRequest
event Action<OctopusResponse> ReceivedOctopusResponse
event Action<OctopusRequest> SendingOctopusRequest
.ctor(Octopus.Client.OctopusServerEndpoint)
Expand Down
6 changes: 3 additions & 3 deletions source/Octopus.Client/IHttpOctopusClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Net;
using System.Net.Http;

namespace Octopus.Client
{
Expand All @@ -11,11 +11,11 @@ public interface IHttpOctopusClient : IOctopusClient
/// <summary>
/// Occurs when a request is about to be sent.
/// </summary>
event Action<WebRequest> BeforeSendingHttpRequest;
event Action<HttpRequestMessage> BeforeSendingHttpRequest;

/// <summary>
/// Occurs when a response has been received.
/// </summary>
event Action<WebResponse> AfterReceivingHttpResponse;
event Action<HttpResponseMessage> AfterReceivingHttpResponse;
}
}
1 change: 1 addition & 0 deletions source/Octopus.Client/Octopus.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

This package contains the client library for the HTTP API in Octopus.</Description>
<NuspecFile>Octopus.Client.nuspec</NuspecFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="!$([MSBuild]::IsOSUnixLike())">
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
Expand Down
16 changes: 12 additions & 4 deletions source/Octopus.Client/OctopusAsyncClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ protected virtual async Task<OctopusResponse<TResponseResource>> DispatchRequest
}
}

SendingOctopusRequest?.Invoke(request);
OnSendingOctopusRequest(request);

BeforeSendingHttpRequest?.Invoke(message);
OnBeforeSendingHttpRequest(message);

if (request.RequestResource != null)
message.Content = GetContent(request);
Expand All @@ -542,7 +542,7 @@ protected virtual async Task<OctopusResponse<TResponseResource>> DispatchRequest
{
using (var response = await client.SendAsync(message, completionOption).ConfigureAwait(false))
{
AfterReceivedHttpResponse?.Invoke(response);
OnAfterReceivedHttpResponse(response);

if (!response.IsSuccessStatusCode)
throw await OctopusExceptionFactory.CreateException(response).ConfigureAwait(false);
Expand All @@ -554,7 +554,7 @@ protected virtual async Task<OctopusResponse<TResponseResource>> DispatchRequest
var locationHeader = response.Headers.Location?.OriginalString;
var octopusResponse = new OctopusResponse<TResponseResource>(request, response.StatusCode,
locationHeader, resource);
ReceivedOctopusResponse?.Invoke(octopusResponse);
OnReceivedOctopusResponse(octopusResponse);

return octopusResponse;
}
Expand All @@ -566,6 +566,14 @@ protected virtual async Task<OctopusResponse<TResponseResource>> DispatchRequest
}
}

protected virtual void OnSendingOctopusRequest(OctopusRequest request) => SendingOctopusRequest?.Invoke(request);

protected virtual void OnBeforeSendingHttpRequest(HttpRequestMessage request) => BeforeSendingHttpRequest?.Invoke(request);

protected virtual void OnAfterReceivedHttpResponse(HttpResponseMessage response) => AfterReceivedHttpResponse?.Invoke(response);

protected virtual void OnReceivedOctopusResponse(OctopusResponse response) => ReceivedOctopusResponse?.Invoke(response);

private HttpContent GetContent(OctopusRequest request)
{
var requestStreamContent = request.RequestResource as Stream;
Expand Down
Loading