use encoding found in HTTP headers in first iteration
This commit is contained in:
2014-01-09 11:49:22 +01:00
parent ef75d87137
commit c3aa9a82b3
3 changed files with 23 additions and 13 deletions
+15 -8
View File
@@ -109,6 +109,10 @@ namespace ReadSharp.Tests
expectedTitle = "Kolik se dá vydělat na volné noze?"; expectedTitle = "Kolik se dá vydělat na volné noze?";
result = await reader.Read(new Uri("http://navolnenoze.cz/blog/vydelky/")); result = await reader.Read(new Uri("http://navolnenoze.cz/blog/vydelky/"));
Assert.Equal(result.Title, expectedTitle); 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); Assert.Equal(result.Title, expectedTitle);
} }
[Fact] //[Fact]
public async Task TestCriticalURIs() //public async Task TestCriticalURIs()
{ //{
Article result = await reader.Read(new Uri("http://www.jetbrains.com/resharper/whatsnew/index.html")); // //Article result = await reader.Read(new Uri("http://www.jetbrains.com/resharper/whatsnew/index.html"));
Assert.NotEmpty(result.Content); // //Assert.NotEmpty(result.Content);
result = await reader.Read(new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx")); // //result = await reader.Read(new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx"));
Assert.NotEmpty(result.Content); // //Assert.NotEmpty(result.Content);
}
// //Article result = await reader.Read(new Uri("http://bit.ly/KAh7FJ"));
// //Assert.NotEmpty(result.Content);
//}
} }
} }
+2 -2
View File
@@ -22,5 +22,5 @@
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.2.1")] [assembly: AssemblyVersion("4.2.2")]
[assembly: AssemblyFileVersion("4.2.1")] [assembly: AssemblyFileVersion("4.2.2")]
+6 -3
View File
@@ -86,8 +86,6 @@ namespace ReadSharp
// add accepted encodings // add accepted encodings
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip,deflate"); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip,deflate");
//_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "UTF-8");
// add user agent // add user agent
string version = Assembly.GetExecutingAssembly().FullName.Split(',')[1].Split('=')[1]; string version = Assembly.GetExecutingAssembly().FullName.Split(',')[1].Split('=')[1];
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", String.Format(_userAgent, "; ReadSharp/" + version)); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", String.Format(_userAgent, "; ReadSharp/" + version));
@@ -142,8 +140,13 @@ namespace ReadSharp
// readability // readability
try 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); encoding = _encoder.GetEncodingFromString(transcodingResult.Charset);
// extract again if encoding didn't match or failed to retrieve // extract again if encoding didn't match or failed to retrieve