Skip to content

Commit a9a0d33

Browse files
authored
Merge pull request #34 from octoper/block-resource-types
[2.x] Added Blocked resource types
2 parents 2430528 + a06d16c commit a9a0d33

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ app.use('/healthcheck', require('express-healthcheck')());
108108
}
109109
}
110110

111+
// Allow to block certain resource types.
112+
// For example: ?blocked_resource_types=image,media
113+
if (query.blocked_resource_types) {
114+
const blockedResourceTypes= query.blocked_resource_types.split(',');
115+
116+
if (blockedResourceTypes.includes(request.resourceType())) {
117+
return request.abort();
118+
}
119+
}
120+
111121
if (query.triggered_requests) {
112122
triggeredRequests.push({
113123
type: request.resourceType(),

src/Clusteer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ public function blockExtensions(array $extensions)
117117
return $this->setParameter('blocked_extensions', implode(',', $extensions));
118118
}
119119

120+
/**
121+
* Set the resource types to block.
122+
*
123+
* @param array $types
124+
* @return $this
125+
*/
126+
public function blockResourceTypes(array $types)
127+
{
128+
return $this->setParameter('blocked_resource_types', implode(',', $types));
129+
}
130+
120131
/**
121132
* Set the timeout.
122133
*

tests/CrawlingTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ public function test_block_extensions()
7575
}
7676
}
7777

78+
public function test_block_resource_types()
79+
{
80+
$blocked_types = [
81+
'image',
82+
];
83+
84+
$clusteer = Clusteer::to('https://renoki.org')
85+
->blockResourceTypes($blocked_types)
86+
->waitUntilAllRequestsFinish()
87+
->withTriggeredRequests()
88+
->get();
89+
90+
foreach ($clusteer->getTriggeredRequests() as $request) {
91+
$this->assertFalse(
92+
(bool) in_array($request['type'], $blocked_types)
93+
);
94+
}
95+
}
96+
7897
public function test_cookies()
7998
{
8099
$this->markTestIncomplete(

0 commit comments

Comments
 (0)