From c3aa9a82b353cd18a20cf0788142270565de10ed Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 9 Jan 2014 11:49:22 +0100 Subject: [PATCH] fixes #6 use encoding found in HTTP headers in first iteration --- ReadSharp.Tests/ReadTests.cs | 23 +++++++++++++++-------- ReadSharp/Properties/AssemblyInfo.cs | 4 ++-- ReadSharp/Reader.cs | 9 ++++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ReadSharp.Tests/ReadTests.cs b/ReadSharp.Tests/ReadTests.cs index 1c1da30..4b48883 100644 --- a/ReadSharp.Tests/ReadTests.cs +++ b/ReadSharp.Tests/ReadTests.cs @@ -109,6 +109,10 @@ namespace ReadSharp.Tests expectedTitle = "Kolik se dá vydělat na volné noze?"; result = await reader.Read(new Uri("http://navolnenoze.cz/blog/vydelky/")); Assert.Equal(result.Title, expectedTitle); + + expectedTitle = "Zkázoděl | dialog.ihned.cz - Komentáře"; + result = await reader.Read(new Uri("http://dialog.ihned.cz/komentare/c1-61530110-zkazodel")); + Assert.Equal(result.Title, expectedTitle); } @@ -120,14 +124,17 @@ namespace ReadSharp.Tests Assert.Equal(result.Title, expectedTitle); } - [Fact] - public async Task TestCriticalURIs() - { - Article result = await reader.Read(new Uri("http://www.jetbrains.com/resharper/whatsnew/index.html")); - Assert.NotEmpty(result.Content); + //[Fact] + //public async Task TestCriticalURIs() + //{ + // //Article result = await reader.Read(new Uri("http://www.jetbrains.com/resharper/whatsnew/index.html")); + // //Assert.NotEmpty(result.Content); - result = await reader.Read(new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx")); - Assert.NotEmpty(result.Content); - } + // //result = await reader.Read(new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx")); + // //Assert.NotEmpty(result.Content); + + // //Article result = await reader.Read(new Uri("http://bit.ly/KAh7FJ")); + // //Assert.NotEmpty(result.Content); + //} } } \ No newline at end of file diff --git a/ReadSharp/Properties/AssemblyInfo.cs b/ReadSharp/Properties/AssemblyInfo.cs index 3431abc..1c4b511 100644 --- a/ReadSharp/Properties/AssemblyInfo.cs +++ b/ReadSharp/Properties/AssemblyInfo.cs @@ -22,5 +22,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.2.1")] -[assembly: AssemblyFileVersion("4.2.1")] \ No newline at end of file +[assembly: AssemblyVersion("4.2.2")] +[assembly: AssemblyFileVersion("4.2.2")] \ No newline at end of file diff --git a/ReadSharp/Reader.cs b/ReadSharp/Reader.cs index b2b17b9..e97759f 100644 --- a/ReadSharp/Reader.cs +++ b/ReadSharp/Reader.cs @@ -86,8 +86,6 @@ namespace ReadSharp // add accepted encodings _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip,deflate"); - //_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "UTF-8"); - // add user agent string version = Assembly.GetExecutingAssembly().FullName.Split(',')[1].Split('=')[1]; _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", String.Format(_userAgent, "; ReadSharp/" + version)); @@ -142,8 +140,13 @@ namespace ReadSharp // readability try { - transcodingResult = ExtractReadableInformation(uri, response.Stream, options); + // charset found in HTTP headers + encoding = _encoder.GetEncodingFromString(response.Charset); + // transcode content + transcodingResult = ExtractReadableInformation(uri, response.Stream, options, encoding); + + // get encoding found in HTML encoding = _encoder.GetEncodingFromString(transcodingResult.Charset); // extract again if encoding didn't match or failed to retrieve