Skip to content

Commit

Permalink
Merge pull request #274 from tmenier/dev
Browse files Browse the repository at this point in the history
PR for Flurl 2.7.0-pre1 & Flurl.Http 2.2.0-pre1
  • Loading branch information
tmenier authored Feb 18, 2018
2 parents 928fa01 + d6b5239 commit 65b55e9
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 93 deletions.
8 changes: 4 additions & 4 deletions PackageTesters/PackageTester.NET45/PackageTester.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Flurl, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.5.1\lib\net40\Flurl.dll</HintPath>
<Reference Include="Flurl, Version=2.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll</HintPath>
</Reference>
<Reference Include="Flurl.Http, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.2.1.0\lib\net45\Flurl.Http.dll</HintPath>
<Reference Include="Flurl.Http, Version=2.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions PackageTesters/PackageTester.NET45/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="Flurl" version="2.5.1" targetFramework="net45" />
<package id="Flurl.Http" version="2.1.0" targetFramework="net45" />
<package id="Flurl" version="2.6.0" targetFramework="net45" />
<package id="Flurl.Http" version="2.1.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Flurl, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.5.1\lib\net40\Flurl.dll</HintPath>
<Reference Include="Flurl, Version=2.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.2.6.0\lib\net45\Flurl.dll</HintPath>
</Reference>
<Reference Include="Flurl.Http, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.2.1.0\lib\net45\Flurl.Http.dll</HintPath>
<Reference Include="Flurl.Http, Version=2.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.2.1.1\lib\net45\Flurl.Http.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions PackageTesters/PackageTester.NET461/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="Flurl" version="2.5.1" targetFramework="net461" />
<package id="Flurl.Http" version="2.1.0" targetFramework="net461" />
<package id="Flurl" version="2.6.0" targetFramework="net461" />
<package id="Flurl.Http" version="2.1.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<Import Project="..\PackageTester.Shared\PackageTester.Shared.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="2.1.0" />
<PackageReference Include="Flurl.Http" Version="2.1.1" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Test/Flurl.Test/Flurl.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netcoreapp1.1;</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp2.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions Test/Flurl.Test/Http/RealHttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,37 @@ namespace Flurl.Test.Http
[TestFixture, Parallelizable]
public class RealHttpTests
{
class StackExResponse
{
public object[] items { get; set; }
public bool has_more { get; set; }
public int backoff { get; set; }

internal static int last_page = 0;
internal static int last_backoff = 0;
}

[TestCase("gzip")]
[TestCase("deflate")]
[NonParallelizable]
public async Task decompresses_automatically(string encoding) {
if (StackExResponse.last_backoff > 0) {
Console.WriteLine($"Backing off StackExchange for {StackExResponse.last_backoff} seconds...");
await Task.Delay(TimeSpan.FromSeconds(StackExResponse.last_backoff));
}

StackExResponse.last_page++;
var result = await $"https://api.stackexchange.com/2.2/answers?site=stackoverflow&pagesize=10"
.SetQueryParam("page", ++StackExResponse.last_page)
.WithHeader("Accept-Encoding", encoding)
.GetJsonAsync<StackExResponse>();

StackExResponse.last_backoff = result.backoff;

Assert.AreEqual(10, result.items.Length);
Assert.IsTrue(result.has_more);
}

[Test]
public async Task can_download_file() {
var folder = "c:\\flurl-test-" + Guid.NewGuid(); // random so parallel tests don't trip over each other
Expand Down
8 changes: 7 additions & 1 deletion Test/Flurl.Test/UrlBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void encodes_illegal_path_chars() {
}

[Test]
public void can_encodes_reserved_path_chars() {
public void can_encode_reserved_path_chars() {
// should encode '/' (tests optional fullyEncode arg)
var url = "http://www.mysite.com".AppendPathSegment("hi there/bye now", true);
Assert.AreEqual("http://www.mysite.com/hi%20there%2Fbye%20now", url.ToString());
Expand Down Expand Up @@ -309,6 +309,12 @@ public void reencodes_encoded_query_values_when_isEncoded_false() {
Assert.AreEqual("http://www.mysite.com?x=%25CD%25EE%25E2%25FB%25E9%2520%25E3%25EE%25E4", url.ToString());
}

[Test]
public void does_not_encode_reserved_chars_in_query_param_name() {
var url = "http://www.mysite.com".SetQueryParam("$x", 1);
Assert.AreEqual("http://www.mysite.com?$x=1", url.ToString());
}

[Test]
public void Url_implicitly_converts_to_string() {
var url = new Url("http://www.mysite.com/more?x=1&y=2");
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

</Project>
6 changes: 5 additions & 1 deletion src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Http;

namespace Flurl.Http.Configuration
Expand Down Expand Up @@ -28,7 +29,10 @@ public virtual HttpClient CreateHttpClient(HttpMessageHandler handler) {
/// customize the result.
/// </summary>
public virtual HttpMessageHandler CreateMessageHandler() {
return new HttpClientHandler();
return new HttpClientHandler {
// #266
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
}
}
}
10 changes: 0 additions & 10 deletions src/Flurl.Http/Configuration/FlurlHttpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,11 @@ public override void ResetDefaults() {
/// </summary>
public class TestFlurlHttpSettings : ClientFlurlHttpSettings
{
/// <summary>
/// Gets or sets the factory that defines creating, caching, and reusing FlurlClient instances
/// within the context of this HttpTest
/// </summary>
public IFlurlClientFactory FlurlClientFactory {
get => Get(() => FlurlClientFactory);
set => Set(() => FlurlClientFactory, value);
}

/// <summary>
/// Resets all test settings to their Flurl.Http-defined default values.
/// </summary>
public override void ResetDefaults() {
base.ResetDefaults();
FlurlClientFactory = new TestFlurlClientFactory();
HttpClientFactory = new TestHttpClientFactory();
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Flurl.Http/Flurl.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netstandard1.3;netstandard1.1;</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.1;netstandard1.3;netstandard2.0;</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl.Http</PackageId>
<Version>2.1.1</Version>
<Version>2.2.0-pre1</Version>
<Authors>Todd Menier</Authors>
<Description>Flurl.Http is a fluent, portable, testable HTTP client library that extends Flurl's URL builder chain.</Description>
<PackageProjectUrl>http://tmenier.github.io/Flurl</PackageProjectUrl>
Expand All @@ -27,14 +27,18 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Flurl" Version="2.6.0" />
<PackageReference Include="Flurl" Version="2.7.0-pre1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1'">
<PackageReference Include="PCLStorage" Version="1.0.2" />
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions src/Flurl.Http/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using System.Dynamic;
using System.IO;
using System.Net.Http;
#if NETSTANDARD1_3
using System.Text;
#endif
using System.Threading.Tasks;
using Flurl.Util;

Expand Down Expand Up @@ -65,8 +62,8 @@ public static async Task<IList<dynamic>> ReceiveJsonList(this Task<HttpResponseM
/// <returns>A Task whose result is the response body as a string.</returns>
/// <example>s = await url.PostAsync(data).ReceiveString()</example>
public static async Task<string> ReceiveString(this Task<HttpResponseMessage> response) {
#if NETSTANDARD1_3
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#if NETSTANDARD1_3 || NETSTANDARD2_0
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
var resp = await response.ConfigureAwait(false);
if (resp == null) return null;
Expand Down
7 changes: 5 additions & 2 deletions src/Flurl.Http/Testing/HttpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Flurl.Http.Testing
/// An object whose existence puts Flurl.Http into test mode where actual HTTP calls are faked. Provides a response
/// queue, call log, and assertion helpers for use in Arrange/Act/Assert style tests.
/// </summary>
#if !NETSTANDARD1_1
[Serializable] // fixes MSTest issue? #207
#endif
public class HttpTest : IDisposable
{
private readonly Lazy<HttpClient> _httpClient;
Expand Down Expand Up @@ -171,7 +174,7 @@ public void Dispose() {
#if NET45
private static void SetCurrentTest(HttpTest test) => System.Runtime.Remoting.Messaging.CallContext.LogicalSetData("FlurlHttpTest", test);
private static HttpTest GetCurrentTest() => System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("FlurlHttpTest") as HttpTest;
#elif NETSTANDARD1_3
#elif NETSTANDARD1_3 || NETSTANDARD2_0
private static System.Threading.AsyncLocal<HttpTest> _test = new System.Threading.AsyncLocal<HttpTest>();
private static void SetCurrentTest(HttpTest test) => _test.Value = test;
private static HttpTest GetCurrentTest() => _test.Value;
Expand All @@ -180,5 +183,5 @@ public void Dispose() {
private static void SetCurrentTest(HttpTest test) => _test = test;
private static HttpTest GetCurrentTest() => _test;
#endif
}
}
}
46 changes: 0 additions & 46 deletions src/Flurl.Http/Testing/TestFactories.cs

This file was deleted.

20 changes: 20 additions & 0 deletions src/Flurl.Http/Testing/TestHttpClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Net.Http;
using Flurl.Http.Configuration;

namespace Flurl.Http.Testing
{
/// <summary>
/// IHttpClientFactory implementation used to fake and record calls in tests.
/// </summary>
public class TestHttpClientFactory : DefaultHttpClientFactory
{
/// <summary>
/// Creates an instance of FakeHttpMessageHander, which prevents actual HTTP calls from being made.
/// </summary>
/// <returns></returns>
public override HttpMessageHandler CreateMessageHandler() {
return new FakeHttpMessageHandler();
}
}
}
4 changes: 2 additions & 2 deletions src/Flurl/Flurl.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net40;net45;netstandard1.3;netstandard1.0;</TargetFrameworks>
<TargetFrameworks>net40;netstandard1.0;netstandard1.3;netstandard2.0;</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl</PackageId>
<Version>2.6.0</Version>
<Version>2.7.0-pre1</Version>
<Authors>Todd Menier</Authors>
<Description>A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http.</Description>
<PackageProjectUrl>http://tmenier.github.io/Flurl</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl/QueryParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ from v in (_value as IEnumerable).Cast<object>()
}

private static string BuildPair(string name, object value, bool valueIsEncoded, bool encodeSpaceAsPlus) {
name = Url.Encode(name, encodeSpaceAsPlus);
name = Url.EncodeIllegalCharacters(name, encodeSpaceAsPlus);
if (value == null)
return name;

Expand Down
11 changes: 8 additions & 3 deletions src/Flurl/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public static string Decode(string s, bool interpretPlusAsSpace) {
/// </summary>
/// <param name="s">The string to encode.</param>
/// <param name="encodeSpaceAsPlus">If true, spaces will be encoded as + signs. Otherwise, they'll be encoded as %20.</param>
/// <returns></returns>
public static string Encode(string s, bool encodeSpaceAsPlus) {
/// <returns>The encoded URL.</returns>
public static string Encode(string s, bool encodeSpaceAsPlus = false) {
if (string.IsNullOrEmpty(s))
return s;

Expand All @@ -164,10 +164,15 @@ public static string Encode(string s, bool encodeSpaceAsPlus) {
/// URL-encodes characters in a string that are neither reserved nor unreserved. Avoids encoding reserved characters such as '/' and '?'. Avoids encoding '%' if it begins a %-hex-hex sequence (i.e. avoids double-encoding).
/// </summary>
/// <param name="s">The string to encode.</param>
public static string EncodeIllegalCharacters(string s) {
/// <param name="encodeSpaceAsPlus">If true, spaces will be encoded as + signs. Otherwise, they'll be encoded as %20.</param>
/// <returns>The encoded URL.</returns>
public static string EncodeIllegalCharacters(string s, bool encodeSpaceAsPlus = false) {
if (string.IsNullOrEmpty(s))
return s;

if (encodeSpaceAsPlus)
s = s.Replace(" ", "+");

// Uri.EscapeUriString mostly does what we want - encodes illegal characters only - but it has a quirk
// in that % isn't illegal if it's the start of a %-encoded sequence https://stackoverflow.com/a/47636037/62600

Expand Down

0 comments on commit 65b55e9

Please sign in to comment.