Skip to content

Commit 46e9ea8

Browse files
author
reef-actor
committed
Move remove_js into dedicated plugin
Script removal is not related to proxification. Class Html removed, no longer referenced.
1 parent 0422e4d commit 46e9ea8

File tree

3 files changed

+31
-193
lines changed

3 files changed

+31
-193
lines changed

src/Html.php

Lines changed: 0 additions & 182 deletions
This file was deleted.

src/Plugin/ProxifyPlugin.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Proxy\Plugin\AbstractPlugin;
66
use Proxy\Event\ProxyEvent;
77
use Proxy\Config;
8-
use Proxy\Html;
98

109
class ProxifyPlugin extends AbstractPlugin {
1110

@@ -153,16 +152,6 @@ public function onCompleted(ProxyEvent $event){
153152
return;
154153
}
155154

156-
// remove JS from urls
157-
$js_remove = (array)Config::get('js_remove');
158-
foreach($js_remove as $pattern){
159-
if(strpos($url_host, $pattern) !== false){
160-
$str = Html::remove_scripts($str);
161-
}
162-
}
163-
164-
// add html.no-js
165-
166155
// let's remove all frames?? does not protect against the frames created dynamically via javascript
167156
$str = preg_replace('@<iframe[^>]*>[^<]*<\\/iframe>@is', '', $str);
168157

src/Plugin/RemoveScriptsPlugin.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
namespace Proxy\Plugin;
3+
4+
use Proxy\Plugin\AbstractPlugin;
5+
use Proxy\Event\ProxyEvent;
6+
use Proxy\Config;
7+
8+
class RemoveScriptsPlugin extends AbstractPlugin
9+
{
10+
public function onCompleted(ProxyEvent $event)
11+
{
12+
$uri = $event['request']->getUri();
13+
$response = $event['response'];
14+
$content_type = $response->headers->get('content-type');
15+
if (strpos($content_type, 'text/html') === false) {
16+
return;
17+
}
18+
19+
$url_host = parse_url($uri, PHP_URL_HOST);
20+
21+
// remove JS from urls
22+
$js_remove = (array)Config::get('js_remove');
23+
foreach ($js_remove as $pattern) {
24+
if (strpos($url_host, $pattern) !== false) {
25+
$content = $response->getContent();
26+
$content = preg_replace('/<\s*script[^>]*>(.*?)<\s*\/\s*script\s*>/is', '', $content);
27+
$response->setContent($content);
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)