From 685f83498c39173efea7ef51c7e265018be922b8 Mon Sep 17 00:00:00 2001 From: Web Addicto Date: Sat, 4 Mar 2017 18:49:09 +0100 Subject: [PATCH 1/2] Support url_pattern_regex Useful to create a plugin that handles more websites (i.e abc.com, abc.de, abc.eu, etc) or similar. --- src/Plugin/AbstractPlugin.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php index 4aa22bc..7129a97 100644 --- a/src/Plugin/AbstractPlugin.php +++ b/src/Plugin/AbstractPlugin.php @@ -10,6 +10,9 @@ abstract class AbstractPlugin implements EventSubscriberInterface { // apply these methods only to those events whose request URL passes this filter protected $url_pattern; + // apply these methods only to those events whose request URL passes this filter (regex) + protected $url_pattern_regex; + public function onBeforeRequest(ProxyEvent $event){ // fired right before a request is being sent to a proxy } @@ -36,6 +39,11 @@ final public function route(ProxyEvent $event){ return; } + // url filter (regex) provided and current request url does not match it + if($this->url_pattern_regex && !preg_match($this->url_pattern_regex, $url)){ + return; + } + switch($event->getName()){ case 'request.before_send': @@ -66,4 +74,4 @@ final public static function getSubscribedEvents(){ } } -?> \ No newline at end of file +?> From 0595954f7858f5dcdc745fbc8549bfb4d2d4bc17 Mon Sep 17 00:00:00 2001 From: Web Addicto Date: Sat, 4 Mar 2017 19:39:59 +0100 Subject: [PATCH 2/2] Updated according to request --- src/Plugin/AbstractPlugin.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php index 7129a97..2b5bc77 100644 --- a/src/Plugin/AbstractPlugin.php +++ b/src/Plugin/AbstractPlugin.php @@ -10,9 +10,6 @@ abstract class AbstractPlugin implements EventSubscriberInterface { // apply these methods only to those events whose request URL passes this filter protected $url_pattern; - // apply these methods only to those events whose request URL passes this filter (regex) - protected $url_pattern_regex; - public function onBeforeRequest(ProxyEvent $event){ // fired right before a request is being sent to a proxy } @@ -35,13 +32,16 @@ final public function route(ProxyEvent $event){ $url = $event['request']->getUri(); // url filter provided and current request url does not match it - if($this->url_pattern && strpos($url, $this->url_pattern) === false){ - return; - } - - // url filter (regex) provided and current request url does not match it - if($this->url_pattern_regex && !preg_match($this->url_pattern_regex, $url)){ - return; + if($this->url_pattern){ + if(strpos($this->url_pattern, '/') === 0){ + if(!preg_match($this->url_pattern, $url)) + return; + } + else + { + if(stripos($url, $this->url_pattern) === false) + return; + } } switch($event->getName()){