Skip to content

Commit

Permalink
Merge pull request #34 from octoper/block-resource-types
Browse files Browse the repository at this point in the history
[2.x] Added Blocked resource types
  • Loading branch information
rennokki authored Sep 21, 2021
2 parents 2430528 + a06d16c commit a9a0d33
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ app.use('/healthcheck', require('express-healthcheck')());
}
}

// Allow to block certain resource types.
// For example: ?blocked_resource_types=image,media
if (query.blocked_resource_types) {
const blockedResourceTypes= query.blocked_resource_types.split(',');

if (blockedResourceTypes.includes(request.resourceType())) {
return request.abort();
}
}

if (query.triggered_requests) {
triggeredRequests.push({
type: request.resourceType(),
Expand Down
11 changes: 11 additions & 0 deletions src/Clusteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public function blockExtensions(array $extensions)
return $this->setParameter('blocked_extensions', implode(',', $extensions));
}

/**
* Set the resource types to block.
*
* @param array $types
* @return $this
*/
public function blockResourceTypes(array $types)
{
return $this->setParameter('blocked_resource_types', implode(',', $types));
}

/**
* Set the timeout.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/CrawlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ public function test_block_extensions()
}
}

public function test_block_resource_types()
{
$blocked_types = [
'image',
];

$clusteer = Clusteer::to('https://renoki.org')
->blockResourceTypes($blocked_types)
->waitUntilAllRequestsFinish()
->withTriggeredRequests()
->get();

foreach ($clusteer->getTriggeredRequests() as $request) {
$this->assertFalse(
(bool) in_array($request['type'], $blocked_types)
);
}
}

public function test_cookies()
{
$this->markTestIncomplete(
Expand Down

0 comments on commit a9a0d33

Please sign in to comment.