Skip to content

Commit 569447c

Browse files
authored
Merge pull request #8 from geeklearningio/release/1.1.1
Release/1.1.1
2 parents 62915c9 + c8e9348 commit 569447c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1016
-85
lines changed

GeekLearning.RestKit.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Core",
77
EndProject
88
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Json", "src\GeekLearning.RestKit.Json\GeekLearning.RestKit.Json.xproj", "{9C387D89-0D16-4279-8B94-37D60DAA7FF5}"
99
EndProject
10+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.Http.Logging", "src\GeekLearning.Http.Logging\GeekLearning.Http.Logging.xproj", "{380EE612-647B-4CDD-B491-B9B4AE7E1479}"
11+
EndProject
12+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.FormData", "src\GeekLearning.RestKit.FormData\GeekLearning.RestKit.FormData.xproj", "{0A64C2AC-3813-46DA-8039-1C79E1950C2A}"
13+
EndProject
14+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Tests", "tests\GeekLearning.RestKit.Tests\GeekLearning.RestKit.Tests.xproj", "{2CFD4C43-C052-42E0-835C-FEA669C4EE91}"
15+
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +27,18 @@ Global
2127
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
2228
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
2329
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Release|Any CPU.Build.0 = Release|Any CPU
2442
EndGlobalSection
2543
GlobalSection(SolutionProperties) = preSolution
2644
HideSolutionNode = FALSE

GitVersion.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
branches:
2+
dev(elop)?(ment)?$:
3+
tag: alpha
4+
features?[/-]:
5+
tag: alpha.{BranchName}
6+
releases?[/-]:
7+
mode: ContinuousDeployment
8+
hotfix(es)?[/-]:
9+
mode: ContinuousDeployment

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "tests" ],
3+
"sdk": {
4+
"version": "1.0.0-preview2-1-003177"
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>380ee612-647b-4cdd-b491-b9b4ae7e1479</ProjectGuid>
11+
<RootNamespace>GeekLearning.Http.Logging</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Net.Http;
6+
using System.Threading;
7+
using Microsoft.Extensions.Logging;
8+
using GeekLearning.D64;
9+
using System.Diagnostics;
10+
11+
namespace GeekLearning.Http.Logging
12+
{
13+
public class HttpRequestLogger : DelegatingHandler
14+
{
15+
private ILogger logger;
16+
private HttpRequestLoggerOptions options;
17+
TimebasedId timebaseId;
18+
19+
public HttpRequestLogger(HttpMessageHandler innerHandler, ILogger logger) : this(innerHandler, logger, new HttpRequestLoggerOptions())
20+
{
21+
}
22+
23+
public HttpRequestLogger(HttpMessageHandler innerHandler, ILogger logger, HttpRequestLoggerOptions options) : base(innerHandler)
24+
{
25+
this.timebaseId = new TimebasedId(false);
26+
this.logger = logger;
27+
this.options = options;
28+
}
29+
30+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
31+
{
32+
var correlationId = timebaseId.NewId();
33+
34+
if (request.Content != null)
35+
{
36+
await request.Content.LoadIntoBufferAsync();
37+
var requestBody = await request.Content.ReadAsStringAsync();
38+
this.logger.LogInformation(
39+
"`{0}` to `{1}` with correlationId `{2}`:\n{3}\n\n{4}",
40+
request.Method,
41+
request.RequestUri,
42+
correlationId,
43+
string.Join("\n", request.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")),
44+
TruncateMessageIfTooBig(requestBody));
45+
}
46+
else
47+
{
48+
this.logger.LogInformation(
49+
"`{0}` to `{1}` with correlationId `{2}`:\n{3}",
50+
request.Method,
51+
request.RequestUri,
52+
correlationId,
53+
string.Join("\n", request.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")));
54+
}
55+
Stopwatch stopwatch = null;
56+
if (this.options.MeasureRequestTime)
57+
{
58+
stopwatch = new Stopwatch();
59+
stopwatch.Start();
60+
}
61+
var response = await base.SendAsync(request, cancellationToken);
62+
await response.Content.LoadIntoBufferAsync();
63+
var responseBody = await response.Content.ReadAsStringAsync();
64+
65+
if (stopwatch != null)
66+
{
67+
stopwatch.Stop();
68+
this.logger.LogInformation(
69+
"`REQUEST` `{0}` ran for `{1}` ms",
70+
correlationId,
71+
stopwatch.Elapsed.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture)
72+
);
73+
}
74+
75+
this.logger.LogInformation(
76+
"`RECEIVE` `{0}` `{1}` with correlationId `{2}`:\n{3}\n\n{4}",
77+
(int)response.StatusCode,
78+
response.ReasonPhrase,
79+
correlationId,
80+
string.Join("\n", response.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")),
81+
TruncateMessageIfTooBig(responseBody));
82+
83+
return response;
84+
}
85+
86+
private string TruncateMessageIfTooBig(string body)
87+
{
88+
if (body.Length > options.MaxSize)
89+
{
90+
return body.Substring(0, options.MaxSize / 2) + "<< TRUNCATED IN LOGS >>" + body.Substring(body.Length - options.MaxSize / 2);
91+
}
92+
else
93+
{
94+
return body;
95+
}
96+
}
97+
98+
}
99+
100+
public class HttpRequestLogger<TInnerHandler> : HttpRequestLogger
101+
where TInnerHandler : HttpMessageHandler, new()
102+
{
103+
public HttpRequestLogger(ILogger logger) : base(new TInnerHandler(), logger)
104+
{
105+
}
106+
}
107+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace GeekLearning.Http.Logging
7+
{
8+
public class HttpRequestLoggerOptions
9+
{
10+
public HttpRequestLoggerOptions() : this(measureRequestTime: true)
11+
{
12+
13+
}
14+
15+
public HttpRequestLoggerOptions(bool measureRequestTime)
16+
{
17+
this.MeasureRequestTime = measureRequestTime;
18+
}
19+
20+
public bool MeasureRequestTime { get; set; }
21+
22+
public int MaxSize { get; set; } = 512000;
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("GeekLearning.Http.Logging")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("380ee612-647b-4cdd-b491-b9b4ae7e1479")]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "1.0.0-*",
3+
4+
"dependencies": {
5+
"Microsoft.Extensions.Logging.Abstractions": "1.1.0",
6+
"NETStandard.Library": "1.6.1",
7+
"GeekLearning.D64": "1.0.0"
8+
},
9+
10+
"frameworks": {
11+
"net452": {},
12+
"netstandard1.3": {
13+
"imports": "dnxcore50"
14+
}
15+
}
16+
}

src/GeekLearning.RestKit.Core/ApiException.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ public abstract class ApiException: Exception
1111
public ApiException()
1212
{
1313
}
14+
15+
public ApiException(HttpResponseMessage response)
16+
{
17+
this.ResponseMessage = response;
18+
}
19+
20+
public HttpResponseMessage ResponseMessage { get; protected set; }
1421
}
1522
}
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
6-
namespace GeekLearning.RestKit.Core
1+
namespace GeekLearning.RestKit.Core
72
{
8-
public abstract class ApiException<TResponse>: ApiException
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Net.Http;
7+
using System.Threading.Tasks;
8+
9+
public class ApiException<TResponse>: ApiException, IApiException<TResponse>
910
{
10-
public ApiException()
11+
public ApiException(HttpResponseMessage response, TResponse data) : base(response)
1112
{
13+
this.Response = data;
1214
}
13-
15+
16+
public TResponse Response { get; }
1417
}
1518
}

0 commit comments

Comments
 (0)