Skip to content

Commit a5563a9

Browse files
committed
Merge pull request anaisbetts#193 from thefex/master
Timeout value is not respected on Android anaisbetts#192
2 parents cec90f3 + a852e77 commit a5563a9

11 files changed

Lines changed: 188 additions & 106 deletions

File tree

ModernHttpClient.sln

Lines changed: 115 additions & 57 deletions
Large diffs are not rendered by default.

src/ModernHttpClient/Android/OkHttpNetworkHandler.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Security.Cryptography.X509Certificates;
1313
using System.Globalization;
1414
using Android.OS;
15+
using Java.Util.Concurrent;
1516

1617
namespace ModernHttpClient
1718
{
@@ -79,6 +80,11 @@ string getHeaderSeparator(string name)
7980

8081
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
8182
{
83+
var timeOut = TimeOut?.TotalMilliseconds ?? 90*1000; // 90 sec is default value provided by orginal HttpClient in .NET
84+
client.SetConnectTimeout((long)timeOut, TimeUnit.Milliseconds);
85+
client.SetWriteTimeout((long) timeOut, TimeUnit.Milliseconds);
86+
client.SetReadTimeout((long)timeOut, TimeUnit.Milliseconds);
87+
8288
var java_uri = request.RequestUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
8389
var url = new Java.Net.URL(java_uri);
8490

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

161167
return ret;
162168
}
169+
170+
/// <summary>
171+
/// Gets or sets the number of milliseconds to wait before the request times out.
172+
/// </summary>
173+
public TimeSpan? TimeOut { get; set; }
163174
}
164175

165176
public static class AwaitableOkHttp

src/ModernHttpClient/Facades.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class NativeMessageHandler : HttpClientHandler
2020
/// </summary>
2121
public NativeMessageHandler(): base()
2222
{
23+
throw new Exception(wrongVersion);
2324
}
2425

2526
/// <summary>
@@ -44,6 +45,14 @@ public void RegisterForProgress(HttpRequestMessage request, ProgressDelegate cal
4445
{
4546
throw new Exception(wrongVersion);
4647
}
48+
49+
/// <summary>
50+
/// Gets or sets the number of milliseconds to wait before the request times out.
51+
/// </summary>
52+
public TimeSpan? TimeOut {
53+
get { throw new Exception(wrongVersion);}
54+
set { throw new Exception(wrongVersion);}
55+
}
4756
}
4857

4958
public class ProgressStreamContent : StreamContent

src/ModernHttpClient/ModernHttpClient.Android.csproj

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -15,7 +15,7 @@
1515
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
1616
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
1717
<AssemblyName>ModernHttpClient</AssemblyName>
18-
<TargetFrameworkVersion>v2.3</TargetFrameworkVersion>
18+
<TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>
1919
</PropertyGroup>
2020
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2121
<DebugSymbols>true</DebugSymbols>
@@ -40,6 +40,14 @@
4040
<ConsolePause>false</ConsolePause>
4141
</PropertyGroup>
4242
<ItemGroup>
43+
<Reference Include="Square.OkHttp, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
44+
<HintPath>..\..\packages\Square.OkHttp.2.5.0.0\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
47+
<Reference Include="Square.OkIO, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
48+
<HintPath>..\..\packages\Square.OkIO.1.6.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
49+
<Private>True</Private>
50+
</Reference>
4351
<Reference Include="System" />
4452
<Reference Include="System.Xml" />
4553
<Reference Include="System.Core" />
@@ -49,21 +57,16 @@
4957
<Compile Include="Android\OkHttpNetworkHandler.cs" />
5058
<None Include="Resources\AboutResources.txt" />
5159
<AndroidResource Include="Resources\values\Strings.xml" />
52-
<Folder Include="Android\Properties\" />
5360
<Compile Include="Android\ConcatenatingStream.cs" />
54-
<Folder Include="Properties\" />
5561
<Compile Include="Properties\AssemblyInfo.cs" />
5662
<Compile Include="ProgressStreamContent.cs" />
5763
<Compile Include="Utility.cs" />
5864
<Compile Include="CaptiveNetworkException.cs" />
5965
<Compile Include="Android\NativeCookieHandler.cs" />
60-
<Reference Include="Square.OkIO">
61-
<HintPath>..\..\packages\Square.OkIO.1.5.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
62-
</Reference>
6366
<None Include="packages.config" />
64-
<Reference Include="Square.OkHttp">
65-
<HintPath>..\..\packages\Square.OkHttp.2.4.0.3\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
66-
</Reference>
67+
</ItemGroup>
68+
<ItemGroup>
69+
<Folder Include="Android\Properties\" />
6770
</ItemGroup>
6871
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
69-
</Project>
72+
</Project>

src/ModernHttpClient/ModernHttpClient.Portable.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -44,4 +44,4 @@
4444
<HintPath>..\..\ext\portable-headers\System.Net.Http.dll</HintPath>
4545
</Reference>
4646
</ItemGroup>
47-
</Project>
47+
</Project>

src/ModernHttpClient/Resources/Resource.designer.cs

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Square.OkHttp" version="2.4.0.3" targetFramework="MonoAndroid23" />
4-
<package id="Square.OkIO" version="1.5.0.0" targetFramework="MonoAndroid23" />
3+
<package id="Square.OkHttp" version="2.5.0.0" targetFramework="monoandroid23" />
4+
<package id="Square.OkIO" version="1.6.0.0" targetFramework="monoandroid23" />
55
</packages>

src/Playground.Android/Playground.Android.csproj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -46,28 +46,30 @@
4646
</CustomCommands>
4747
</PropertyGroup>
4848
<ItemGroup>
49+
<Reference Include="Square.OkHttp, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
50+
<HintPath>..\..\packages\Square.OkHttp.2.5.0.0\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
51+
<Private>True</Private>
52+
</Reference>
53+
<Reference Include="Square.OkIO, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Square.OkIO.1.6.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
4957
<Reference Include="System" />
5058
<Reference Include="System.Xml" />
5159
<Reference Include="System.Core" />
5260
<Reference Include="Mono.Android" />
5361
<Reference Include="System.Net.Http" />
54-
<Reference Include="Square.OkIO">
55-
<HintPath>..\..\packages\Square.OkIO.1.5.0.0\lib\MonoAndroid\Square.OkIO.dll</HintPath>
56-
</Reference>
57-
<Reference Include="Square.OkHttp">
58-
<HintPath>..\..\packages\Square.OkHttp.2.4.0.3\lib\MonoAndroid\Square.OkHttp.dll</HintPath>
59-
</Reference>
6062
</ItemGroup>
6163
<ItemGroup>
6264
<Compile Include="MainActivity.cs" />
6365
<Compile Include="Resources\Resource.designer.cs" />
6466
<Compile Include="Properties\AssemblyInfo.cs" />
6567
</ItemGroup>
6668
<ItemGroup>
69+
<None Include="packages.config" />
6770
<None Include="Resources\AboutResources.txt" />
6871
<None Include="Assets\AboutAssets.txt" />
6972
<None Include="Properties\AndroidManifest.xml" />
70-
<None Include="packages.config" />
7173
</ItemGroup>
7274
<ItemGroup>
7375
<AndroidResource Include="Resources\layout\Main.axml" />
@@ -81,4 +83,4 @@
8183
<Name>ModernHttpClient.Android</Name>
8284
</ProjectReference>
8385
</ItemGroup>
84-
</Project>
86+
</Project>

src/Playground.Android/Resources/Resource.designer.cs

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Square.OkHttp" version="2.4.0.3" targetFramework="MonoAndroid403" />
4-
<package id="Square.OkIO" version="1.5.0.0" targetFramework="MonoAndroid403" />
3+
<package id="Square.OkHttp" version="2.5.0.0" targetFramework="monoandroid403" />
4+
<package id="Square.OkIO" version="1.6.0.0" targetFramework="monoandroid403" />
55
</packages>

0 commit comments

Comments
 (0)