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 };
|
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);
|
Assert.Equal(result.PageCount, 9);
|
||||||
|
|
||||||
result = await reader.Read(new Uri("http://www.zeit.de/gesellschaft/2014-02/alice-schwarzer-steuerhinterziehung-doppelmoral"), options);
|
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>
|
/// </summary>
|
||||||
protected HttpOptions _options;
|
protected HttpOptions _options;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current pages
|
||||||
|
/// </summary>
|
||||||
|
protected List<string> _currentPages = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Redirect faulty mobile URIs to desktop equivalents
|
/// Redirect faulty mobile URIs to desktop equivalents
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -118,6 +123,8 @@ namespace ReadSharp
|
|||||||
/// <exception cref="OperationCanceledException"></exception>
|
/// <exception cref="OperationCanceledException"></exception>
|
||||||
public async Task<Article> Read(Uri uri, ReadOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<Article> Read(Uri uri, ReadOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
|
_currentPages = new List<string>();
|
||||||
|
|
||||||
Response response;
|
Response response;
|
||||||
string uriString = uri.OriginalString;
|
string uriString = uri.OriginalString;
|
||||||
|
|
||||||
@@ -274,6 +281,13 @@ namespace ReadSharp
|
|||||||
/// </exception>
|
/// </exception>
|
||||||
private async Task<Response> Request(Uri uri, ReadOptions options, Response previousResponse, CancellationToken cancellationToken)
|
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;
|
HttpResponseMessage response = null;
|
||||||
TranscodingResult transcodingResult;
|
TranscodingResult transcodingResult;
|
||||||
Encoding encoding;
|
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.
|
// 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 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;
|
previousResponse.TranscodingResult.NextPageUrl = null;
|
||||||
return previousResponse;
|
return previousResponse;
|
||||||
|
|||||||
Reference in New Issue
Block a user