Skip to content

Commit

Permalink
Remove dependency on Microsoft.AspNet.WebApi.Client (#996)
Browse files Browse the repository at this point in the history
* Using an alias for System.Net.Http.Formatting

* .

* fix

* space
  • Loading branch information
StefH authored Aug 29, 2023
1 parent 93c8784 commit 59aab9e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion PackageReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ For more details see also [Docker](https://github.com/WireMock-Net/WireMock.Net-
More details on using HTTPS (SSL) can be found here [Wiki : HTTPS](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-(SSL))

## :books: Documentation
For more info, see also this WIKI page: [What is WireMock.Net](https://github.com/WireMock-Net/WireMock.Net/wiki/What-Is-WireMock.Net).
For more info, see also this WIKI page: [What is WireMock.Net](https://github.com/WireMock-Net/WireMock.Net/wiki/What-Is-WireMock.Net).
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\WireMock.Net\Http\HttpClientFactory2.cs" Link="Http\HttpClientFactory2.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="IsExternalInit" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Stef.Validation" Version="0.1.1" />
<PackageReference Include="Testcontainers" Version="3.2.0" />
<PackageReference Include="JetBrains.Annotations" VersionOverride="2022.3.1" PrivateAssets="All" Version="2022.3.1" />
Expand All @@ -33,4 +36,8 @@
<ItemGroup>
<ProjectReference Include="..\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Http\" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions src/WireMock.Net.Testcontainers/WireMockContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using RestEase;
using Stef.Validation;
using WireMock.Client;
using WireMock.Http;

namespace WireMock.Net.Testcontainers;

Expand Down Expand Up @@ -71,7 +72,7 @@ public HttpClient CreateClient(params DelegatingHandler[] handlers)
{
ValidateIfRunning();

var client = HttpClientFactory.Create(handlers);
var client = HttpClientFactory2.Create(handlers);
client.BaseAddress = GetPublicUri();
return client;
}
Expand All @@ -93,7 +94,7 @@ public HttpClient CreateClient(HttpMessageHandler innerHandler, params Delegatin
{
ValidateIfRunning();

var client = HttpClientFactory.Create(innerHandler, handlers);
var client = HttpClientFactory2.Create(innerHandler, handlers);
client.BaseAddress = GetPublicUri();
return client;
}
Expand Down
33 changes: 23 additions & 10 deletions src/WireMock.Net/Http/HttpClientFactory2.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Net.Http;

namespace WireMock.Http;
Expand All @@ -6,19 +7,31 @@ internal static class HttpClientFactory2
{
public static HttpClient Create(params DelegatingHandler[] handlers)
{
#if NETSTANDARD1_3
return new HttpClient();
#else
return HttpClientFactory.Create(handlers);
#endif
var handler = CreateHandlerPipeline(new HttpClientHandler(), handlers);
return new HttpClient(handler);
}

public static HttpClient Create(HttpMessageHandler innerHandler, params DelegatingHandler[] handlers)
{
#if NETSTANDARD1_3
return new HttpClient(innerHandler);
#else
return HttpClientFactory.Create(innerHandler, handlers);
#endif
var handler = CreateHandlerPipeline(innerHandler, handlers);
return new HttpClient(handler);
}

private static HttpMessageHandler CreateHandlerPipeline(HttpMessageHandler handler, params DelegatingHandler[] delegatingHandlers)
{
if (delegatingHandlers.Length == 0)
{
return handler;
}

var next = handler;

foreach (var delegatingHandler in delegatingHandlers.Reverse())
{
delegatingHandler.InnerHandler = next;
next = delegatingHandler;
}

return next;
}
}
1 change: 0 additions & 1 deletion src/WireMock.Net/WireMock.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
<PackageReference Include="XPath2.Extensions" Version="1.1.3" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.8" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'net452' ">
Expand Down
4 changes: 1 addition & 3 deletions test/WireMock.Net.Tests/WireMock.Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<PackageReference Include="NFluent" Version="2.8.0" />
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
<PackageReference Include="AnyOf" Version="0.3.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452' or '$(TargetFramework)' == 'net461'">
Expand Down Expand Up @@ -134,7 +135,4 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup>
<Folder Include="Pact\files\" />
</ItemGroup>
</Project>

0 comments on commit 59aab9e

Please sign in to comment.