This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea55c82
commit 0ebd9bf
Showing
18 changed files
with
654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyProduct("Polly.Extensions.Http")] | ||
[assembly: AssemblyCompany("App vNext")] | ||
[assembly: AssemblyDescription("Polly.Extensions.Http is an extensions package containing opinionated convenience methods for configuring Polly policies to handle transient faults typical of calls through HttpClient.")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2018, App vNext")] | ||
|
||
#if DEBUG | ||
[assembly: AssemblyConfiguration("Debug")] | ||
#else | ||
[assembly: AssemblyConfiguration("Release")] | ||
#endif |
33 changes: 33 additions & 0 deletions
33
...s.Http.NetStandard11-Signed.Specs/Polly.Extensions.Http.NetStandard11-Signed.Specs.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
<OutputTypeEx>library</OutputTypeEx> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<DefineConstants>TRACE;RELEASE;NETCOREAPP1_1</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="4.19.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> | ||
<PackageReference Include="Polly-Signed" Version="5.8.0" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Polly.Extensions.Http.NetStandard11-Signed\Polly.Extensions.Http.NetStandard11-Signed.csproj" /> | ||
</ItemGroup> | ||
<Import Project="..\Polly.Extensions.Http.SharedSpecs\Polly.Extensions.Http.SharedSpecs.projitems" Label="Shared" /> | ||
</Project> |
1 change: 1 addition & 0 deletions
1
src/Polly.Extensions.Http.NetStandard11-Signed.Specs/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[assembly: Xunit.CollectionBehavior(DisableTestParallelization = false)] |
34 changes: 34 additions & 0 deletions
34
...ly.Extensions.Http.NetStandard11-Signed/Polly.Extensions.Http.NetStandard11-Signed.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>Polly.Extensions.Http</AssemblyName> | ||
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile> | ||
<DefineConstants>TRACE;PORTABLE</DefineConstants> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<RootNamespace>PolicyExtensions</RootNamespace> | ||
<TargetFramework>netstandard1.1</TargetFramework> | ||
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<NuSpecFile Include="$(SolutionDir)Polly.Extensions.Http.nuspec"> | ||
<Visible>False</Visible> | ||
</NuSpecFile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Polly-Signed" Version="5.8.0" /> | ||
</ItemGroup> | ||
<Import Project="..\Polly.Extensions.Http.Shared\Polly.Extensions.Http.Shared.projitems" Label="Shared" /> | ||
</Project> |
9 changes: 9 additions & 0 deletions
9
src/Polly.Extensions.Http.NetStandard11-Signed/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Polly.Extensions.Http")] | ||
[assembly: AssemblyVersion("0.1.0.0")] | ||
[assembly: CLSCompliant(true)] | ||
|
||
[assembly: InternalsVisibleTo("Polly.Extensions.Http.NetStandard11-Signed.Specs")] |
33 changes: 33 additions & 0 deletions
33
...olly.Extensions.Http.NetStandard11.Specs/Polly.Extensions.Http.NetStandard11.Specs.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
<OutputTypeEx>library</OutputTypeEx> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<DefineConstants>TRACE;RELEASE;NETCOREAPP1_1</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="4.19.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> | ||
<PackageReference Include="Polly" Version="5.8.0" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Polly.Extensions.Http.NetStandard11\Polly.Extensions.Http.NetStandard11.csproj" /> | ||
</ItemGroup> | ||
<Import Project="..\Polly.Extensions.Http.SharedSpecs\Polly.Extensions.Http.SharedSpecs.projitems" Label="Shared" /> | ||
</Project> |
1 change: 1 addition & 0 deletions
1
src/Polly.Extensions.Http.NetStandard11.Specs/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[assembly: Xunit.CollectionBehavior(DisableTestParallelization = false)] |
34 changes: 34 additions & 0 deletions
34
src/Polly.Extensions.Http.NetStandard11/Polly.Extensions.Http.NetStandard11.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>Polly.Extensions.Http</AssemblyName> | ||
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile> | ||
<DefineConstants>TRACE;PORTABLE</DefineConstants> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<RootNamespace>PolicyExtensions</RootNamespace> | ||
<TargetFramework>netstandard1.1</TargetFramework> | ||
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<NuSpecFile Include="$(SolutionDir)Polly.Extensions.Http.nuspec"> | ||
<Visible>False</Visible> | ||
</NuSpecFile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Polly" Version="5.8.0" /> | ||
</ItemGroup> | ||
<Import Project="..\Polly.Extensions.Http.Shared\Polly.Extensions.Http.Shared.projitems" Label="Shared" /> | ||
</Project> |
9 changes: 9 additions & 0 deletions
9
src/Polly.Extensions.Http.NetStandard11/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyTitle("Polly.Extensions.Http")] | ||
[assembly: AssemblyVersion("0.1.0.0")] | ||
[assembly: CLSCompliant(true)] | ||
|
||
[assembly: InternalsVisibleTo("Polly.Extensions.Http.NetStandard11.Specs")] |
115 changes: 115 additions & 0 deletions
115
src/Polly.Extensions.Http.Shared/HttpPolicyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
|
||
namespace Polly.Extensions.Http | ||
{ | ||
/// <summary> | ||
/// Contains opinionated convenience methods for configuring policies to handle conditions typically representing transient faults when making <see cref="HttpClient"/> requests. | ||
/// </summary> | ||
public static class HttpPolicyExtensions | ||
{ | ||
private static readonly Func<HttpResponseMessage, bool> TransientHttpStatusCodePredicate = (response) => | ||
{ | ||
return (int)response.StatusCode >= 500 || response.StatusCode == HttpStatusCode.RequestTimeout; | ||
}; | ||
|
||
/// <summary> | ||
/// Builds a <see cref="PolicyBuilder{HttpResponseMessage}"/> to configure a <see cref="Policy{HttpResponseMessage}"/> which will handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. | ||
/// <para>The conditions configured to be handled are: | ||
/// <list type="bullet"> | ||
/// <item><description>Network failures (as <see cref="HttpRequestException"/>)</description></item> | ||
/// <item><description>HTTP 5XX status codes (server errors)</description></item> | ||
/// <item><description>HTTP 408 status code (request timeout)</description></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <returns>The <see cref="PolicyBuilder{HttpResponseMessage}"/> pre-configured to handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. </returns> | ||
public static PolicyBuilder<HttpResponseMessage> HandleTransientHttpError() | ||
{ | ||
return Policy<HttpResponseMessage>.Handle<HttpRequestException>().OrTransientHttpStatusCode(); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the <see cref="PolicyBuilder{HttpResponseMessage}"/> to handle <see cref="HttpClient"/> requests that fail with <see cref="HttpStatusCode"/>s indicating a transient failure. | ||
/// <para>The <see cref="HttpStatusCode"/>s configured to be handled are: | ||
/// <list type="bullet"> | ||
/// <item><description>HTTP 5XX status codes (server errors)</description></item> | ||
/// <item><description>HTTP 408 status code (request timeout)</description></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <returns>The <see cref="PolicyBuilder{HttpResponseMessage}"/> pre-configured to handle <see cref="HttpClient"/> requests that fail with <see cref="HttpStatusCode"/>s indicating a transient failure. </returns> | ||
public static PolicyBuilder<HttpResponseMessage> OrTransientHttpStatusCode(this PolicyBuilder policyBuilder) | ||
{ | ||
if (policyBuilder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(policyBuilder)); | ||
} | ||
|
||
return policyBuilder.OrResult(TransientHttpStatusCodePredicate); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the <see cref="PolicyBuilder{HttpResponseMessage}"/> to handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. | ||
/// <para>The conditions configured to be handled are: | ||
/// <list type="bullet"> | ||
/// <item><description>Network failures (as <see cref="HttpRequestException"/>)</description></item> | ||
/// <item><description>HTTP 5XX status codes (server errors)</description></item> | ||
/// <item><description>HTTP 408 status code (request timeout)</description></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <returns>The <see cref="PolicyBuilder{HttpResponseMessage}"/> pre-configured to handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. </returns> | ||
public static PolicyBuilder<HttpResponseMessage> OrTransientHttpError(this PolicyBuilder policyBuilder) | ||
{ | ||
if (policyBuilder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(policyBuilder)); | ||
} | ||
|
||
return policyBuilder.Or<HttpRequestException>().OrTransientHttpStatusCode(); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the <see cref="PolicyBuilder{HttpResponseMessage}"/> to handle <see cref="HttpClient"/> requests that fail with <see cref="HttpStatusCode"/>s indicating a transient failure. | ||
/// <para>The <see cref="HttpStatusCode"/>s configured to be handled are: | ||
/// <list type="bullet"> | ||
/// <item><description>HTTP 5XX status codes (server errors)</description></item> | ||
/// <item><description>HTTP 408 status code (request timeout)</description></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <returns>The <see cref="PolicyBuilder{HttpResponseMessage}"/> pre-configured to handle <see cref="HttpClient"/> requests that fail with <see cref="HttpStatusCode"/>s indicating a transient failure. </returns> | ||
public static PolicyBuilder<HttpResponseMessage> OrTransientHttpStatusCode(this PolicyBuilder<HttpResponseMessage> policyBuilder) | ||
{ | ||
if (policyBuilder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(policyBuilder)); | ||
} | ||
|
||
return policyBuilder.OrResult(TransientHttpStatusCodePredicate); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the <see cref="PolicyBuilder{HttpResponseMessage}"/> to handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. | ||
/// <para>The conditions configured to be handled are: | ||
/// <list type="bullet"> | ||
/// <item><description>Network failures (as <see cref="HttpRequestException"/>)</description></item> | ||
/// <item><description>HTTP 5XX status codes (server errors)</description></item> | ||
/// <item><description>HTTP 408 status code (request timeout)</description></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <returns>The <see cref="PolicyBuilder{HttpResponseMessage}"/> pre-configured to handle <see cref="HttpClient"/> requests that fail with conditions indicating a transient failure. </returns> | ||
public static PolicyBuilder<HttpResponseMessage> OrTransientHttpError(this PolicyBuilder<HttpResponseMessage> policyBuilder) | ||
{ | ||
if (policyBuilder == null) | ||
{ | ||
throw new ArgumentNullException(nameof(policyBuilder)); | ||
} | ||
|
||
return policyBuilder.Or<HttpRequestException>().OrTransientHttpStatusCode(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Polly.Extensions.Http.Shared/Polly.Extensions.Http.Shared.projitems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<SharedGUID>23fa87f9-c77d-4c67-a0b0-2901de51b3ff</SharedGUID> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<Import_RootNamespace>Polly.Extensions.Http.Shared</Import_RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)HttpPolicyExtensions.cs" /> | ||
</ItemGroup> | ||
</Project> |
13 changes: 13 additions & 0 deletions
13
src/Polly.Extensions.Http.Shared/Polly.Extensions.Http.Shared.shproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>23fa87f9-c77d-4c67-a0b0-2901de51b3ff</ProjectGuid> | ||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" /> | ||
<PropertyGroup /> | ||
<Import Project="Polly.Extensions.Http.Shared.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" /> | ||
</Project> |
Oops, something went wrong.