diff --git a/src/Html.php b/src/Html.php
deleted file mode 100644
index 08c4c40..0000000
--- a/src/Html.php
+++ /dev/null
@@ -1,182 +0,0 @@
-]*>(.*?)<\s*\/\s*script\s*>/is', '', $html);
- return $html;
- }
-
- public static function remove_styles($html){
- $html = preg_replace('/<\s*style[^>]*>(.*?)<\s*\/\s*style\s*>/is', '', $html);
- return $html;
- }
-
- public static function remove_comments($html){
- return preg_replace('//s', '', $html);
- }
-
- private static function find($selector, $html, $start_from = 0){
-
- $html = substr($html, $start_from);
-
- $inner_start = 0;
- $inner_end = 0;
-
- $pattern = '//';
-
- if(substr($selector, 0, 1) == '#'){
- $pattern = '/<(\w+)[^>]+id="'.substr($selector, 1).'"[^>]*>/is';
- } else if(substr($selector, 0, 1) == '.'){
- $pattern = '/<(\w+)[^>]+class="'.substr($selector, 1).'"[^>]*>/is';
- } else {
- return false;
- }
-
- if(preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)){
-
- $outer_start = $matches[0][1];
- $inner_start = $matches[0][1] + strlen($matches[0][0]);
-
- // tag stuff
- $tag_name = $matches[1][0];
- $tag_len = strlen($tag_name);
-
- $run_count = 300;
-
- // "open" 0){
-
- $open_tag = strpos($html, "<{$tag_name}", $start);
- $close_tag = strpos($html, "{$tag_name}", $start);
-
- // nothing was found?
- if($open_tag === false && $close_tag === false){
- break;
- }
-
- //echo "open_tag: {$open_tag}, close_tag {$close_tag}\r\n";
-
- // found OPEN tag
- if($close_tag === false || ($open_tag !== false && $open_tag < $close_tag) ){
- $open_count++;
- $start = $open_tag + $tag_len + 1;
-
- //echo "found open tag: ".substr($html, $open_tag, 20)." at {$open_tag} \r\n";
-
- // found CLOSE tag
- } else if($open_tag === false || ($close_tag !== false && $close_tag < $open_tag) ){
- $open_count--;
- $start = $close_tag + $tag_len + 2;
-
- //echo "found close tag: ".substr($html, $close_tag, 20)." at {$close_tag} \r\n";
- }
- }
-
- // something went wrong... don't bother returning anything
- if($open_count != 0){
- return false;
- }
-
- $outer_end = $close_tag + $tag_len + 3;
- $inner_end = $close_tag;
-
- return array(
- 'outer_start' => $outer_start + $start_from,
- 'inner_start' => $inner_start + $start_from,
- 'inner_end' => $inner_end + $start_from,
- 'outer_end' => $outer_end + $start_from
- );
- }
-
- return false;
- }
-
- public static function extract_inner($selector, $html){
- return self::extract($selector, $html, true);
- }
-
- public static function extract_outer($selector, $html){
- return self::extract($selector, $html, false);
- }
-
- private static function extract($selector, $html, $inner = false){
-
- $pos = 0;
- $limit = 300;
-
- $result = array();
- $data = false;
-
- do {
-
- $data = self::find($selector, $html, $pos);
-
- if($data){
-
- $code = substr($html, $inner ? $data['inner_start'] : $data['outer_start'],
- $inner ? $data['inner_end'] - $data['inner_start'] : $data['outer_end'] - $data['outer_start']);
-
- $result[] = $code;
- $pos = $data['outer_end'];
- }
-
- } while ($data && --$limit > 0);
-
- return $result;
- }
-
- public static function remove($selector, $html){
- return self::replace($selector, '', $html, false);
- }
-
- public static function replace_outer($selector, $replace, $html, &$matches = NULL){
- return self::replace($selector, $replace, $html, false, $matches);
- }
-
- public static function replace_inner($selector, $replace, $html, &$matches = NULL){
- return self::replace($selector, $replace, $html, true, $matches);
- }
-
- private static function replace($selector, $replace, $html, $replace_inner = false, &$matches = NULL){
-
- $start_from = 0;
- $limit = 300;
-
- $data = false;
- $replace = (array)$replace;
-
- do {
-
- $data = self::find($selector, $html, $start_from);
-
- if($data){
-
- $r = array_shift($replace);
-
- // from where to where will we be replacing?
- $replace_space = $replace_inner ? $data['inner_end'] - $data['inner_start'] : $data['outer_end'] - $data['outer_start'];
- $replace_len = strlen($r);
-
- if($matches !== NULL){
- $matches[] = substr($html, $replace_inner ? $data['inner_start'] : $data['outer_start'], $replace_space);
- }
-
- $html = substr_replace($html, $r, $replace_inner ? $data['inner_start'] : $data['outer_start'], $replace_space);
-
- // next time we resume search at position right at the end of this element
- $start_from = $data['outer_end'] + ($replace_len - $replace_space);
- }
-
- } while ($data && --$limit > 0);
-
- return $html;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php
index 605cee3..69771b0 100644
--- a/src/Plugin/AbstractPlugin.php
+++ b/src/Plugin/AbstractPlugin.php
@@ -4,78 +4,62 @@
use Proxy\Event\ProxyEvent;
-abstract class AbstractPlugin {
-
- // apply these methods only to those events whose request URL passes this filter
- protected $url_pattern;
-
- public function onBeforeRequest(ProxyEvent $event){
- // fired right before a request is being sent to a proxy
- }
-
- public function onHeadersReceived(ProxyEvent $event){
- // fired right after response headers have been fully received - last chance to modify before sending it back to the user
- }
-
- public function onCurlWrite(ProxyEvent $event){
- // fired as the data is being written piece by piece
- }
-
- public function onCompleted(ProxyEvent $event){
- // fired after the full response=headers+body has been read - will only be called on "non-streaming" responses
- }
-
- final public function subscribe($dispatcher){
-
- $dispatcher->addListener('request.before_send', function($event){
- $this->route('request.before_send', $event);
- });
-
- $dispatcher->addListener('request.sent', function($event){
- $this->route('request.sent', $event);
- });
-
- $dispatcher->addListener('curl.callback.write', function($event){
- $this->route('curl.callback.write', $event);
- });
-
- $dispatcher->addListener('request.complete', function($event){
- $this->route('request.complete', $event);
- });
- }
-
- // dispatch based on filter
- final private function route($event_name, ProxyEvent $event){
- $url = $event['request']->getUri();
-
- // url filter provided and current request url does not match it
- if($this->url_pattern){
- if(starts_with($this->url_pattern, '/') && preg_match($this->url_pattern, $url) !== 1){
- return;
- } else if(stripos($url, $this->url_pattern) === false){
- return;
- }
- }
-
- switch($event_name){
-
- case 'request.before_send':
- $this->onBeforeRequest($event);
- break;
-
- case 'request.sent':
- $this->onHeadersReceived($event);
- break;
-
- case 'curl.callback.write':
- $this->onCurlWrite($event);
- break;
-
- case 'request.complete':
- $this->onCompleted($event);
- break;
- }
- }
-}
+abstract class AbstractPlugin
+{
+ const EVENT_LISTENERS = [
+ 'request.before_send' => 'onBeforeRequest',
+ 'request.sent' => 'onHeadersReceived',
+ 'curl.callback.write' => 'onCurlWrite',
+ 'request.complete' => 'onCompleted',
+ ];
+
+ // apply these methods only to those events whose request URL passes this filter
+ protected $url_pattern;
+
+ public function onBeforeRequest(ProxyEvent $event)
+ {
+ // fired right before a request is being sent to a proxy
+ }
+
+ public function onHeadersReceived(ProxyEvent $event)
+ {
+ // fired right after response headers have been fully received - last chance to modify before sending it back to the user
+ }
+
+ public function onCurlWrite(ProxyEvent $event)
+ {
+ // fired as the data is being written piece by piece
+ }
+
+ public function onCompleted(ProxyEvent $event)
+ {
+ // fired after the full response=headers+body has been read - will only be called on "non-streaming" responses
+ }
-?>
+ final public function subscribe($dispatcher)
+ {
+ foreach (self::EVENT_LISTENERS as $event_name => $listener) {
+ $dispatcher->addListener($event_name, function ($event) use ($event_name) {
+ $this->route($event_name, $event);
+ });
+ }
+ }
+
+ // dispatch based on filter
+ final private function route($event_name, ProxyEvent $event)
+ {
+ $url = $event['request']->getUri();
+
+ // url filter provided and current request url does not match it
+ if ($this->url_pattern) {
+ if (starts_with($this->url_pattern, '/') && preg_match($this->url_pattern, $url) !== 1) {
+ return;
+ } else if (stripos($url, $this->url_pattern) === false) {
+ return;
+ }
+ }
+
+ // Call the handler for this event
+ [$this, self::EVENT_LISTENERS[$event_name]]($event);
+ }
+}
diff --git a/src/Plugin/ProxifyPlugin.php b/src/Plugin/ProxifyPlugin.php
index 3165428..11b4c65 100644
--- a/src/Plugin/ProxifyPlugin.php
+++ b/src/Plugin/ProxifyPlugin.php
@@ -1,202 +1,82 @@
\'|")\d+\s*;\s*url=(?.*?)\k@is' => 'self::proxifyUrlCallback', // content="X;url=" (meta-refresh)
+ '@\b(?:src|href)\s*=\s*(?\'|")(?.*?)\k@is' => 'self::proxifyUrlCallback', // src="" & href=""
+ '@[^a-z]{1}url\s*\((?\'|"|)(?[^\)]*)\k\)@im' => 'self::proxifyUrlCallback', // url()
+ '@\@import\s+(?\'|")(?.*?)\k@im' => 'self::proxifyUrlCallback', // @import ''
+ '@\b(?:srcset)\s*=\s*(?\'|")(?.*?)\k@im' => 'self::proxifySrcsetAttributeCallback', // srcset=" xxx, …"
+ '@<\s*form[^>]*action=(?\'|")(?.*?)\k[^>]*>@im' => 'self::proxifyFormCallback', //