Skip to content

Commit

Permalink
Fixed some issues when cloning HttpBehavior or HttpSettings
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
Lakritzator committed Jun 9, 2016
1 parent 581a6f3 commit 65831fc
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<HintPath>..\packages\Dapplo.LogFacade.0.2.45\lib\net45\Dapplo.LogFacade.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Utils, Version=0.1.33.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.33\lib\net45\Dapplo.Utils.dll</HintPath>
<Reference Include="Dapplo.Utils, Version=0.1.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.42\lib\net45\Dapplo.Utils.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.HttpExtensions.Net45/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapplo.LogFacade" version="0.2.45" targetFramework="net45" />
<package id="Dapplo.Utils" version="0.1.33" targetFramework="net45" />
<package id="Dapplo.Utils" version="0.1.42" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion Dapplo.HttpExtensions.PCL/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"Dapplo.LogFacade": "0.2.45",
"Dapplo.Utils": "0.1.33",
"Dapplo.Utils": "0.1.42",
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0",
"System.ComponentModel": "4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions Dapplo.HttpExtensions.Shared/HttpBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#region using

using Dapplo.Utils;
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand Down Expand Up @@ -116,10 +117,10 @@ public static IHttpBehaviour Current
public int ReadBufferSize { get; set; } = HttpExtensionsGlobals.ReadBufferSize;

/// <inheritdoc />
public IChangeableHttpBehaviour Clone()
public IChangeableHttpBehaviour ShallowClone()
{
var result = (HttpBehaviour) MemberwiseClone();
result.HttpSettings = HttpSettings.Clone();
result.HttpSettings = HttpSettings.ShallowClone();
return result;
}

Expand Down
9 changes: 2 additions & 7 deletions Dapplo.HttpExtensions.Shared/IHttpBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#region using

using Dapplo.Utils;
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand All @@ -33,7 +34,7 @@ namespace Dapplo.HttpExtensions
/// <summary>
/// The IHttpBehaviour is used to control the behaviour of all operations in the HttpExtensions library.
/// </summary>
public interface IHttpBehaviour
public interface IHttpBehaviour : IShallowCloneable<IChangeableHttpBehaviour>
{
/// <summary>
/// Specify if the progress actions (UploadProgress or DownloadProcess) are called
Expand Down Expand Up @@ -135,12 +136,6 @@ public interface IHttpBehaviour
/// </summary>
bool ValidateResponseContentType { get; }

/// <summary>
/// Clone this HttpBehavior and return an interface which can be used to write
/// </summary>
/// <returns>IChangeableHttpBehaviour</returns>
IChangeableHttpBehaviour Clone();

/// <summary>
/// Set this IHttpBehaviour on the CallContext
/// </summary>
Expand Down
11 changes: 3 additions & 8 deletions Dapplo.HttpExtensions.Shared/IHttpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#region using

using Dapplo.Utils;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
Expand All @@ -47,9 +48,9 @@ namespace Dapplo.HttpExtensions
/// <see cref="HttpExtensionsGlobals" />
/// </summary>
#if _PCL_
public interface IHttpSettings
public interface IHttpSettings : IShallowCloneable<IHttpSettings>
#else
public partial interface IHttpSettings
public partial interface IHttpSettings : IShallowCloneable<IHttpSettings>
#endif
{
/// <summary>
Expand Down Expand Up @@ -137,11 +138,5 @@ public partial interface IHttpSettings
/// </summary>
[DefaultValue(true), Display(Description = "When true every http request will supply the default user credentials when the server asks for them"), DataMember(EmitDefaultValue = true)]
bool UseDefaultCredentials { get; set; }

/// <summary>
/// Clone this IHttpSettings
/// </summary>
/// <returns>IHttpSettings</returns>
IHttpSettings Clone();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class OAuth2HttpBehaviourFactory
public static IHttpBehaviour Create(OAuth2Settings oAuth2Settings, IHttpBehaviour fromHttpBehaviour = null)
{
// Get a clone of a IHttpBehaviour (passed or current)
var oauthHttpBehaviour = (fromHttpBehaviour ?? HttpBehaviour.Current).Clone();
var oauthHttpBehaviour = (fromHttpBehaviour ?? HttpBehaviour.Current).ShallowClone();
// Add a wrapper (delegate handler) which wraps all new HttpMessageHandlers
oauthHttpBehaviour.ChainOnHttpMessageHandlerCreated(httpMessageHandler => new OAuth2HttpMessageHandler(oAuth2Settings, oauthHttpBehaviour, httpMessageHandler));
return oauthHttpBehaviour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public OAuth2HttpMessageHandler(OAuth2Settings oAuth2Settings, IHttpBehaviour ht
}

_oAuth2Settings = oAuth2Settings;
var newHttpBehaviour = httpBehaviour.Clone();
var newHttpBehaviour = httpBehaviour.ShallowClone();
// Remove the OnHttpMessageHandlerCreated
newHttpBehaviour.OnHttpMessageHandlerCreated = null;
// Use it for internal communication
Expand Down Expand Up @@ -280,7 +280,7 @@ private async Task GenerateRefreshTokenAsync(CancellationToken cancellationToken
}
}

var normalHttpBehaviour = _httpBehaviour.Clone();
var normalHttpBehaviour = _httpBehaviour.ShallowClone();
normalHttpBehaviour.OnHttpMessageHandlerCreated = null;
normalHttpBehaviour.MakeCurrent();

Expand Down
5 changes: 3 additions & 2 deletions Dapplo.HttpExtensions.Shared/Support/HttpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Reflection;
using System.Text;
using System.Net.Http;
using Dapplo.Utils;

#if !_PCL_
using System.Net.Cache;
Expand All @@ -44,7 +45,7 @@ namespace Dapplo.HttpExtensions.Support
/// Most have their normal defaults, which would also normally be used, some have special settings
/// The default values and the property descriptions are in the IHttpSettings (which can be used by Dapplo.Config)
/// </summary>
public class HttpSettings : IHttpSettings
public class HttpSettings : IHttpSettings, IShallowCloneable<IHttpSettings>
{
private const int Kb = 1024;
private const int Mb = Kb*1024;
Expand Down Expand Up @@ -164,7 +165,7 @@ public string DefaultUserAgent
/// This is needed by the HttpBehaviour to prevent that a modification of a copy is changing the global settings!
/// </summary>
/// <returns></returns>
public IHttpSettings Clone()
public IHttpSettings ShallowClone()
{
return (IHttpSettings)MemberwiseClone();
}
Expand Down
3 changes: 2 additions & 1 deletion Dapplo.HttpExtensions.SharedDesktop/IHttpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#region using

using Dapplo.Utils;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
Expand Down Expand Up @@ -50,7 +51,7 @@ namespace Dapplo.HttpExtensions
/// (Yes, it's can be empty, the settings are in the IHttpSettings interface) and than assign the generated instance to
/// <see cref="HttpExtensionsGlobals" />
/// </summary>
public partial interface IHttpSettings
public partial interface IHttpSettings : IShallowCloneable<IHttpSettings>
{
/// <summary>
/// For more details, click
Expand Down
11 changes: 8 additions & 3 deletions Dapplo.HttpExtensions.SharedDesktop/OAuth/OAuth1HttpBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#region using

using Dapplo.Utils;
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand All @@ -44,7 +45,7 @@ public class OAuth1HttpBehaviour : IChangeableHttpBehaviour
/// <param name="httpBehaviour">IHttpBehaviour to wrap</param>
public OAuth1HttpBehaviour(IHttpBehaviour httpBehaviour = null)
{
_wrapped = (httpBehaviour ?? HttpBehaviour.Current).Clone();
_wrapped = (httpBehaviour ?? HttpBehaviour.Current).ShallowClone();
}

/// <summary>
Expand Down Expand Up @@ -170,9 +171,13 @@ public bool ValidateResponseContentType
}

/// <inheritdoc />
public IChangeableHttpBehaviour Clone()
public IChangeableHttpBehaviour ShallowClone()
{
return (OAuth1HttpBehaviour) MemberwiseClone();
// the wrapper object will be clone when creating the OAuth1HttpBehaviour
var result = new OAuth1HttpBehaviour(_wrapped);
result.OnAccessTokenValues = OnAccessTokenValues;
result.BeforeSend = BeforeSend;
return result;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public OAuth1HttpMessageHandler(OAuth1Settings oAuth1Settings, OAuth1HttpBehavio

_oAuth1Settings = oAuth1Settings;

var newHttpBehaviour = (OAuth1HttpBehaviour)oAuth1HttpBehaviour.Clone();
var newHttpBehaviour = oAuth1HttpBehaviour.ShallowClone();
// Remove the OnHttpMessageHandlerCreated
newHttpBehaviour.OnHttpMessageHandlerCreated = null;
// Use it for internal communication
_oAuth1HttpBehaviour = newHttpBehaviour;
_oAuth1HttpBehaviour = (OAuth1HttpBehaviour)newHttpBehaviour;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task TestHttpBehaviourChaining()
bool testChainOnHttpMessageHandlerCreated1 = false;
bool testChainOnHttpMessageHandlerCreated2 = false;

var testBehaviour = HttpBehaviour.Current.Clone();
var testBehaviour = HttpBehaviour.Current.ShallowClone();

testBehaviour.ChainOnHttpContentCreated(x => {
testChainOnHttpContentCreated1 = true;
Expand Down
4 changes: 2 additions & 2 deletions Dapplo.HttpExtensions.Tests.Shared/HttpPartsPostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public HttpPartsPostTest(ITestOutputHelper testOutputHelper)
public async Task TestPost_Bitmap()
{
var testUri = RequestBinUri.AppendSegments("post");
var uploadBehaviour = HttpBehaviour.Current.Clone();
var uploadBehaviour = HttpBehaviour.Current.ShallowClone();

bool hasProgress = false;

Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task TestPost_Bitmap()
public async Task TestPost_BitmapSource()
{
var testUri = RequestBinUri.AppendSegments("post");
var uploadBehaviour = HttpBehaviour.Current.Clone();
var uploadBehaviour = HttpBehaviour.Current.ShallowClone();

bool hasProgress = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task TestGetAsAsync204()
[Fact]
public async Task TestGetAsAsyncBitmap()
{
var downloadBehaviour = HttpBehaviour.Current.Clone();
var downloadBehaviour = HttpBehaviour.Current.ShallowClone();

downloadBehaviour.UseProgressStream = true;
downloadBehaviour.DownloadProgress += progress => { Log.Info().WriteLine("Progress {0}", (int) (progress*100)); };
Expand All @@ -108,7 +108,7 @@ public async Task TestGetAsAsyncBitmap()
public async Task TestGetAsAsyncBitmapSource()
{

var uploadBehaviour = HttpBehaviour.Current.Clone();
var uploadBehaviour = HttpBehaviour.Current.ShallowClone();

bool hasProgress = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<HintPath>..\packages\Dapplo.LogFacade.0.2.45\lib\net45\Dapplo.LogFacade.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Utils, Version=0.1.33.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.33\lib\net45\Dapplo.Utils.dll</HintPath>
<Reference Include="Dapplo.Utils, Version=0.1.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.42\lib\net45\Dapplo.Utils.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.HttpExtensions.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="coveralls.io" version="1.3.4" targetFramework="net46" />
<package id="Dapplo.LogFacade" version="0.2.45" targetFramework="net46" />
<package id="Dapplo.Utils" version="0.1.33" targetFramework="net46" />
<package id="Dapplo.Utils" version="0.1.42" targetFramework="net46" />
<package id="OpenCover" version="4.6.519" targetFramework="net46" />
<package id="xunit" version="2.1.0" targetFramework="net46" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net46" />
Expand Down
10 changes: 5 additions & 5 deletions Dapplo.HttpExtensions.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<dependencies>
<group targetFramework="net46">
<dependency id="Dapplo.LogFacade" version="0.2.45" />
<dependency id="Dapplo.Utils" version="0.1.30" />
<dependency id="Dapplo.Utils" version="0.1.42" />
</group>
<group targetFramework="net45">
<dependency id="Dapplo.LogFacade" version="0.2.45" />
<dependency id="Dapplo.Utils" version="0.1.30" />
<dependency id="Dapplo.Utils" version="0.1.42" />
</group>
<group targetFramework="dnxcore50">
<dependency id="System.Net.Http" version="4.0.0" />
Expand All @@ -32,7 +32,7 @@
<dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.0.10" />
<dependency id="Dapplo.LogFacade" version="0.2.45" />
<dependency id="Dapplo.Utils" version="0.1.30" />
<dependency id="Dapplo.Utils" version="0.1.42" />
</group>
<group targetFramework="uap10.0">
<dependency id="System.Net.Http" version="4.0.0" />
Expand All @@ -41,7 +41,7 @@
<dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.0.10" />
<dependency id="Dapplo.LogFacade" version="0.2.45" />
<dependency id="Dapplo.Utils" version="0.1.30" />
<dependency id="Dapplo.Utils" version="0.1.42" />
</group>
<group targetFramework="dotnet">
<dependency id="System.Net.Http" version="4.0.0" />
Expand All @@ -50,7 +50,7 @@
<dependency id="System.Dynamic.Runtime" version="4.0.10" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.0.10" />
<dependency id="Dapplo.LogFacade" version="0.2.45" />
<dependency id="Dapplo.Utils" version="0.1.30" />
<dependency id="Dapplo.Utils" version="0.1.42" />
</group>
</dependencies>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions Dapplo.HttpExtensions/Dapplo.HttpExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<HintPath>..\packages\Dapplo.LogFacade.0.2.45\lib\net45\Dapplo.LogFacade.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Utils, Version=0.1.33.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.33\lib\net45\Dapplo.Utils.dll</HintPath>
<Reference Include="Dapplo.Utils, Version=0.1.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.0.1.42\lib\net45\Dapplo.Utils.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.HttpExtensions/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapplo.LogFacade" version="0.2.45" targetFramework="net46" />
<package id="Dapplo.Utils" version="0.1.33" targetFramework="net46" />
<package id="Dapplo.Utils" version="0.1.42" targetFramework="net46" />
<package id="System.Runtime.Serialization.Primitives" version="4.0.10" targetFramework="net46" />
</packages>

0 comments on commit 65831fc

Please sign in to comment.