Skip to content

Commit

Permalink
Merge pull request anaisbetts#193 from thefex/master
Browse files Browse the repository at this point in the history
 Timeout value is not respected on Android anaisbetts#192
  • Loading branch information
fabionuno committed Nov 20, 2015
2 parents cec90f3 + a852e77 commit a5563a9
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 106 deletions.
172 changes: 115 additions & 57 deletions ModernHttpClient.sln

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/ModernHttpClient/Android/OkHttpNetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Security.Cryptography.X509Certificates;
using System.Globalization;
using Android.OS;
using Java.Util.Concurrent;

namespace ModernHttpClient
{
Expand Down Expand Up @@ -79,6 +80,11 @@ string getHeaderSeparator(string name)

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var timeOut = TimeOut?.TotalMilliseconds ?? 90*1000; // 90 sec is default value provided by orginal HttpClient in .NET
client.SetConnectTimeout((long)timeOut, TimeUnit.Milliseconds);
client.SetWriteTimeout((long) timeOut, TimeUnit.Milliseconds);
client.SetReadTimeout((long)timeOut, TimeUnit.Milliseconds);

var java_uri = request.RequestUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
var url = new Java.Net.URL(java_uri);

Expand Down Expand Up @@ -160,6 +166,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

return ret;
}

/// <summary>
/// Gets or sets the number of milliseconds to wait before the request times out.
/// </summary>
public TimeSpan? TimeOut { get; set; }
}

public static class AwaitableOkHttp
Expand Down
9 changes: 9 additions & 0 deletions src/ModernHttpClient/Facades.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class NativeMessageHandler : HttpClientHandler
/// </summary>
public NativeMessageHandler(): base()
{
throw new Exception(wrongVersion);
}

/// <summary>
Expand All @@ -44,6 +45,14 @@ public void RegisterForProgress(HttpRequestMessage request, ProgressDelegate cal
{
throw new Exception(wrongVersion);
}

/// <summary>
/// Gets or sets the number of milliseconds to wait before the request times out.
/// </summary>
public TimeSpan? TimeOut {
get { throw new Exception(wrongVersion);}
set { throw new Exception(wrongVersion);}
}
}

public class ProgressStreamContent : StreamContent
Expand Down
25 changes: 14 additions & 11 deletions src/ModernHttpClient/ModernHttpClient.Android.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -15,7 +15,7 @@
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AssemblyName>ModernHttpClient</AssemblyName>
<TargetFrameworkVersion>v2.3</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -40,6 +40,14 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="Square.OkHttp, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Square.OkHttp.2.5.0.0\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Square.OkIO, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Square.OkIO.1.6.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
Expand All @@ -49,21 +57,16 @@
<Compile Include="Android\OkHttpNetworkHandler.cs" />
<None Include="Resources\AboutResources.txt" />
<AndroidResource Include="Resources\values\Strings.xml" />
<Folder Include="Android\Properties\" />
<Compile Include="Android\ConcatenatingStream.cs" />
<Folder Include="Properties\" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProgressStreamContent.cs" />
<Compile Include="Utility.cs" />
<Compile Include="CaptiveNetworkException.cs" />
<Compile Include="Android\NativeCookieHandler.cs" />
<Reference Include="Square.OkIO">
<HintPath>..\..\packages\Square.OkIO.1.5.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
</Reference>
<None Include="packages.config" />
<Reference Include="Square.OkHttp">
<HintPath>..\..\packages\Square.OkHttp.2.4.0.3\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Android\Properties\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/ModernHttpClient/ModernHttpClient.Portable.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -44,4 +44,4 @@
<HintPath>..\..\ext\portable-headers\System.Net.Http.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
</Project>
20 changes: 10 additions & 10 deletions src/ModernHttpClient/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ModernHttpClient/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="Square.OkHttp" version="2.4.0.3" targetFramework="MonoAndroid23" />
<package id="Square.OkIO" version="1.5.0.0" targetFramework="MonoAndroid23" />
<package id="Square.OkHttp" version="2.5.0.0" targetFramework="monoandroid23" />
<package id="Square.OkIO" version="1.6.0.0" targetFramework="monoandroid23" />
</packages>
20 changes: 11 additions & 9 deletions src/Playground.Android/Playground.Android.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -46,28 +46,30 @@
</CustomCommands>
</PropertyGroup>
<ItemGroup>
<Reference Include="Square.OkHttp, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Square.OkHttp.2.5.0.0\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Square.OkIO, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Square.OkIO.1.6.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="System.Net.Http" />
<Reference Include="Square.OkIO">
<HintPath>..\..\packages\Square.OkIO.1.5.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
</Reference>
<Reference Include="Square.OkHttp">
<HintPath>..\..\packages\Square.OkHttp.2.4.0.3\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
Expand All @@ -81,4 +83,4 @@
<Name>ModernHttpClient.Android</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
20 changes: 10 additions & 10 deletions src/Playground.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Playground.Android/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="Square.OkHttp" version="2.4.0.3" targetFramework="MonoAndroid403" />
<package id="Square.OkIO" version="1.5.0.0" targetFramework="MonoAndroid403" />
<package id="Square.OkHttp" version="2.5.0.0" targetFramework="monoandroid403" />
<package id="Square.OkIO" version="1.6.0.0" targetFramework="monoandroid403" />
</packages>
5 changes: 2 additions & 3 deletions src/Playground.iOS/Playground.iOS.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -12,7 +12,6 @@
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<AssemblyName>PlaygroundiOS</AssemblyName>
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -132,4 +131,4 @@
<Name>ModernHttpClient.iOS64</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>

0 comments on commit a5563a9

Please sign in to comment.