Skip to content

Commit

Permalink
Add handling of origin protocol scheme to reply if sent.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbairwell committed Apr 19, 2016
1 parent 5544c35 commit cd697d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/MiddlewareCors/Traits/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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;
}
}
}
Expand All @@ -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()

/**
Expand Down

0 comments on commit cd697d5

Please sign in to comment.