From cd697d5f8443b319070d411fa018bfc581117220 Mon Sep 17 00:00:00 2001 From: Richard Bairwell Date: Tue, 19 Apr 2016 17:05:40 +0000 Subject: [PATCH] Add handling of origin protocol scheme to reply if sent. --- CHANGELOG.md | 2 ++ src/MiddlewareCors/Traits/Parse.php | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30dd14..44a25a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +v0.3.5 - 19th Apr 2016 + Add handling of origin protocol scheme to reply if sent. v0.3.0 - 13th Apr 2016 Added handling of origins which are fully qualified ( such as http://example.com/ instead of just hostname) v0.2.0 - 5th Jan 2016 diff --git a/src/MiddlewareCors/Traits/Parse.php b/src/MiddlewareCors/Traits/Parse.php index e06c12c..1ab9b00 100644 --- a/src/MiddlewareCors/Traits/Parse.php +++ b/src/MiddlewareCors/Traits/Parse.php @@ -172,10 +172,15 @@ protected function parseOrigin(ServerRequestInterface $request) : string // lowercase the user provided origin for comparison purposes. $origin = strtolower($origin); $parsed = parse_url($origin); + $protocol=''; if (true === is_array($parsed) && true === isset($parsed['host'])) { $this->addLog('Parsed a hostname from origin: '.$parsed['host']); $origin = $parsed['host']; } + if (true===is_array($parsed) && true===isset($parsed['scheme'])) { + $this->addLog('Parsed a protocol from origin: '.$parsed['scheme']); + $protocol=$parsed['scheme'].'://'; + } // read the current origin setting $originSetting = $this->settings['origin']; @@ -200,7 +205,7 @@ protected function parseOrigin(ServerRequestInterface $request) : string // if anything else but '' was returned, then we have a valid match. if ('' !== $matched) { $this->addLog('Iterator found a matched origin of '.$matched); - return $matched; + return $protocol.$matched; } } } @@ -213,7 +218,11 @@ protected function parseOrigin(ServerRequestInterface $request) : string } // return the matched setting (may be '' to indicate nothing matched) - return $matched; + if (''===$matched) { + return ''; + } else { + return $protocol.$matched; + } }//end parseOrigin() /**