Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
857fa98
Merge pull request #2 from geeklearningio/master
sandorfr Sep 27, 2016
84aa3d1
add gitversion config
sandorfr Sep 27, 2016
2f36675
Merge branch 'develop' of https://github.com/geeklearningio/gl-dotnet…
sandorfr Sep 27, 2016
72a1be5
Merge branch 'develop' of https://github.com/geeklearningio/gl-dotnet…
sandorfr Sep 27, 2016
4328036
Merge branch 'develop' of https://github.com/geeklearningio/gl-dotnet…
sandorfr Sep 27, 2016
7dd4413
add response to unhandled api exception
sandorfr Sep 27, 2016
c639a57
add first HttpHandlerFactory primitives
sandorfr Dec 7, 2016
981ceda
add http logging primitives
sandorfr Dec 9, 2016
adc6320
make constructors public
sandorfr Dec 9, 2016
7b87fcc
Use Load into Buffer
sandorfr Dec 9, 2016
fc9601f
Get compatibility
sandorfr Dec 9, 2016
4a185ca
fix response logging
sandorfr Dec 10, 2016
358d2ba
header values format
sandorfr Dec 15, 2016
71a6569
await read content
sandorfr Dec 15, 2016
fc4137e
status code as int
sandorfr Dec 15, 2016
9d7b3a3
measure timings
sandorfr Dec 20, 2016
45f2739
add message body truncate if too large
sandorfr Dec 23, 2016
db33c53
multipart/formdata support
sandorfr Dec 25, 2016
2d73505
formdata
sandorfr Dec 25, 2016
fb80a74
api exception and status mapping
sandorfr Dec 26, 2016
79142f0
exception mapping fixes
sandorfr Dec 27, 2016
9d5765e
Polly options
sandorfr Dec 27, 2016
23c3e6b
deduplicate get media formatter
sandorfr Dec 29, 2016
4026f47
Fix `UnsupportedMediaType` exception
sandorfr Jan 12, 2017
99ba7e9
fix #6
sandorfr Jan 30, 2017
5be1474
Merge pull request #7 from geeklearningio/feature/fix-no-content-parsing
sandorfr Jan 30, 2017
1b9d25a
make sure there is content in the body prior to trying finding a form…
sandorfr Feb 1, 2017
80cea15
fix generic exception ancestors
sandorfr Feb 1, 2017
ea4e124
fix FileFactory method visibility
sandorfr Mar 10, 2017
82b00ee
fix file formData
sandorfr Mar 13, 2017
967a9b5
switch form data to netstandard 1.3
sandorfr Mar 13, 2017
72dc98f
fix IFile support
sandorfr Mar 13, 2017
c8e9348
Add missing SafeToString to ClientBase
sandorfr Mar 28, 2017
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
18 changes: 18 additions & 0 deletions GeekLearning.RestKit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Core",
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Json", "src\GeekLearning.RestKit.Json\GeekLearning.RestKit.Json.xproj", "{9C387D89-0D16-4279-8B94-37D60DAA7FF5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.Http.Logging", "src\GeekLearning.Http.Logging\GeekLearning.Http.Logging.xproj", "{380EE612-647B-4CDD-B491-B9B4AE7E1479}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.FormData", "src\GeekLearning.RestKit.FormData\GeekLearning.RestKit.FormData.xproj", "{0A64C2AC-3813-46DA-8039-1C79E1950C2A}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "GeekLearning.RestKit.Tests", "tests\GeekLearning.RestKit.Tests\GeekLearning.RestKit.Tests.xproj", "{2CFD4C43-C052-42E0-835C-FEA669C4EE91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +27,18 @@ Global
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C387D89-0D16-4279-8B94-37D60DAA7FF5}.Release|Any CPU.Build.0 = Release|Any CPU
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Debug|Any CPU.Build.0 = Debug|Any CPU
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Release|Any CPU.ActiveCfg = Release|Any CPU
{380EE612-647B-4CDD-B491-B9B4AE7E1479}.Release|Any CPU.Build.0 = Release|Any CPU
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A64C2AC-3813-46DA-8039-1C79E1950C2A}.Release|Any CPU.Build.0 = Release|Any CPU
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CFD4C43-C052-42E0-835C-FEA669C4EE91}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 9 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
branches:
dev(elop)?(ment)?$:
tag: alpha
features?[/-]:
tag: alpha.{BranchName}
releases?[/-]:
mode: ContinuousDeployment
hotfix(es)?[/-]:
mode: ContinuousDeployment
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "tests" ],
"sdk": {
"version": "1.0.0-preview2-1-003177"
}
}
21 changes: 21 additions & 0 deletions src/GeekLearning.Http.Logging/GeekLearning.Http.Logging.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>380ee612-647b-4cdd-b491-b9b4ae7e1479</ProjectGuid>
<RootNamespace>GeekLearning.Http.Logging</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
107 changes: 107 additions & 0 deletions src/GeekLearning.Http.Logging/HttpRequestLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Threading;
using Microsoft.Extensions.Logging;
using GeekLearning.D64;
using System.Diagnostics;

namespace GeekLearning.Http.Logging
{
public class HttpRequestLogger : DelegatingHandler
{
private ILogger logger;
private HttpRequestLoggerOptions options;
TimebasedId timebaseId;

public HttpRequestLogger(HttpMessageHandler innerHandler, ILogger logger) : this(innerHandler, logger, new HttpRequestLoggerOptions())
{
}

public HttpRequestLogger(HttpMessageHandler innerHandler, ILogger logger, HttpRequestLoggerOptions options) : base(innerHandler)
{
this.timebaseId = new TimebasedId(false);
this.logger = logger;
this.options = options;
}

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var correlationId = timebaseId.NewId();

if (request.Content != null)
{
await request.Content.LoadIntoBufferAsync();
var requestBody = await request.Content.ReadAsStringAsync();
this.logger.LogInformation(
"`{0}` to `{1}` with correlationId `{2}`:\n{3}\n\n{4}",
request.Method,
request.RequestUri,
correlationId,
string.Join("\n", request.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")),
TruncateMessageIfTooBig(requestBody));
}
else
{
this.logger.LogInformation(
"`{0}` to `{1}` with correlationId `{2}`:\n{3}",
request.Method,
request.RequestUri,
correlationId,
string.Join("\n", request.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")));
}
Stopwatch stopwatch = null;
if (this.options.MeasureRequestTime)
{
stopwatch = new Stopwatch();
stopwatch.Start();
}
var response = await base.SendAsync(request, cancellationToken);
await response.Content.LoadIntoBufferAsync();
var responseBody = await response.Content.ReadAsStringAsync();

if (stopwatch != null)
{
stopwatch.Stop();
this.logger.LogInformation(
"`REQUEST` `{0}` ran for `{1}` ms",
correlationId,
stopwatch.Elapsed.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture)
);
}

this.logger.LogInformation(
"`RECEIVE` `{0}` `{1}` with correlationId `{2}`:\n{3}\n\n{4}",
(int)response.StatusCode,
response.ReasonPhrase,
correlationId,
string.Join("\n", response.Headers.Select(h => $"{h.Key}: {string.Join(" ", h.Value)}")),
TruncateMessageIfTooBig(responseBody));

return response;
}

private string TruncateMessageIfTooBig(string body)
{
if (body.Length > options.MaxSize)
{
return body.Substring(0, options.MaxSize / 2) + "<< TRUNCATED IN LOGS >>" + body.Substring(body.Length - options.MaxSize / 2);
}
else
{
return body;
}
}

}

public class HttpRequestLogger<TInnerHandler> : HttpRequestLogger
where TInnerHandler : HttpMessageHandler, new()
{
public HttpRequestLogger(ILogger logger) : base(new TInnerHandler(), logger)
{
}
}
}
24 changes: 24 additions & 0 deletions src/GeekLearning.Http.Logging/HttpRequestLoggerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GeekLearning.Http.Logging
{
public class HttpRequestLoggerOptions
{
public HttpRequestLoggerOptions() : this(measureRequestTime: true)
{

}

public HttpRequestLoggerOptions(bool measureRequestTime)
{
this.MeasureRequestTime = measureRequestTime;
}

public bool MeasureRequestTime { get; set; }

public int MaxSize { get; set; } = 512000;
}
}
19 changes: 19 additions & 0 deletions src/GeekLearning.Http.Logging/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GeekLearning.Http.Logging")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("380ee612-647b-4cdd-b491-b9b4ae7e1479")]
16 changes: 16 additions & 0 deletions src/GeekLearning.Http.Logging/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "1.0.0-*",

"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "1.1.0",
"NETStandard.Library": "1.6.1",
"GeekLearning.D64": "1.0.0"
},

"frameworks": {
"net452": {},
"netstandard1.3": {
"imports": "dnxcore50"
}
}
}
7 changes: 7 additions & 0 deletions src/GeekLearning.RestKit.Core/ApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ public abstract class ApiException: Exception
public ApiException()
{
}

public ApiException(HttpResponseMessage response)
{
this.ResponseMessage = response;
}

public HttpResponseMessage ResponseMessage { get; protected set; }
}
}
21 changes: 12 additions & 9 deletions src/GeekLearning.RestKit.Core/ApiException{TResponse}.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GeekLearning.RestKit.Core
namespace GeekLearning.RestKit.Core
{
public abstract class ApiException<TResponse>: ApiException
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

public class ApiException<TResponse>: ApiException, IApiException<TResponse>
{
public ApiException()
public ApiException(HttpResponseMessage response, TResponse data) : base(response)
{
this.Response = data;
}


public TResponse Response { get; }
}
}
28 changes: 21 additions & 7 deletions src/GeekLearning.RestKit.Core/BadRequestApiException.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GeekLearning.RestKit.Core
namespace GeekLearning.RestKit.Core
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

public class BadRequestApiException: ApiException
{
public BadRequestApiException()
{
}

public BadRequestApiException(HttpResponseMessage message): base(message)
{
}
}

public class BadRequestApiException<TResponse> : ApiException<TResponse>
public class BadRequestApiException<TResponse> : BadRequestApiException, IApiException<TResponse>
{
public BadRequestApiException(HttpResponseMessage message, TResponse response) : base(message)
{
this.Response = response;
}

public TResponse Response { get; }
}
}
Loading