improve security, that no double content is fetched
This commit is contained in:
@@ -180,7 +180,10 @@ namespace ReadSharp.Tests
|
||||
{
|
||||
ReadOptions options = new ReadOptions() { MultipageDownload = true };
|
||||
|
||||
Article result = await reader.Read(new Uri("http://www.anandtech.com/show/7594/samsung-ssd-840-evo-msata-120gb-250gb-500gb-1tb-review"), options);
|
||||
Article result = await reader.Read(new Uri("http://www.maximumpc.com/article/features/modders_toolkit_everything_you_need_make_kick-ass_custom_case_mods"), options);
|
||||
Assert.Equal(result.PageCount, 4);
|
||||
|
||||
result = await reader.Read(new Uri("http://www.anandtech.com/show/7594/samsung-ssd-840-evo-msata-120gb-250gb-500gb-1tb-review"), options);
|
||||
Assert.Equal(result.PageCount, 9);
|
||||
|
||||
result = await reader.Read(new Uri("http://www.zeit.de/gesellschaft/2014-02/alice-schwarzer-steuerhinterziehung-doppelmoral"), options);
|
||||
|
||||
+15
-1
@@ -39,6 +39,11 @@ namespace ReadSharp
|
||||
/// </summary>
|
||||
protected HttpOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// The current pages
|
||||
/// </summary>
|
||||
protected List<string> _currentPages = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Redirect faulty mobile URIs to desktop equivalents
|
||||
/// </summary>
|
||||
@@ -118,6 +123,8 @@ namespace ReadSharp
|
||||
/// <exception cref="OperationCanceledException"></exception>
|
||||
public async Task<Article> Read(Uri uri, ReadOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
_currentPages = new List<string>();
|
||||
|
||||
Response response;
|
||||
string uriString = uri.OriginalString;
|
||||
|
||||
@@ -274,6 +281,13 @@ namespace ReadSharp
|
||||
/// </exception>
|
||||
private async Task<Response> Request(Uri uri, ReadOptions options, Response previousResponse, CancellationToken cancellationToken)
|
||||
{
|
||||
// URI already fetched
|
||||
if (previousResponse != null && _currentPages.Contains(uri.OriginalString))
|
||||
{
|
||||
return previousResponse;
|
||||
}
|
||||
_currentPages.Add(uri.OriginalString);
|
||||
|
||||
HttpResponseMessage response = null;
|
||||
TranscodingResult transcodingResult;
|
||||
Encoding encoding;
|
||||
@@ -354,7 +368,7 @@ namespace ReadSharp
|
||||
|
||||
// in same special cases their are multiple pages, which are only comments or do not contain new content.
|
||||
// if this is the case we will break here and return the first page only.
|
||||
if (previousResponse != null && previousResponse.TranscodingResult.ExtractedContent == transcodingResult.ExtractedContent)
|
||||
if (previousResponse != null && previousResponse.TranscodingResult.ExtractedContent.Contains(transcodingResult.ExtractedContent))
|
||||
{
|
||||
previousResponse.TranscodingResult.NextPageUrl = null;
|
||||
return previousResponse;
|
||||
|
||||
Reference in New Issue
Block a user