Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing ->header() to ->headers->set() #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions LumenCors.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
class LumenCors {

protected $settings = array(
'origin' => '*', // Wide Open!
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
);
'origin' => '*', // Wide Open!
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
);

protected function setOrigin($req, $rsp) {
$origin = $this->settings['origin'];
if (is_callable($origin)) {
// Call origin callback with request origin
$origin = call_user_func($origin,
$req->header("Origin")
);
$origin = call_user_func($origin,$req->header("Origin"));
}
$rsp->header('Access-Control-Allow-Origin', $origin);
$rsp->headers->set('Access-Control-Allow-Origin', $origin);
}

protected function setExposeHeaders($req, $rsp) {
Expand All @@ -27,20 +25,20 @@ protected function setExposeHeaders($req, $rsp) {
if (is_array($exposeHeaders)) {
$exposeHeaders = implode(", ", $exposeHeaders);
}
$rsp->header('Access-Control-Expose-Headers', $exposeHeaders);

$rsp->headers->set('Access-Control-Expose-Headers', $exposeHeaders);
}
}

protected function setMaxAge($req, $rsp) {
if (isset($this->settings['maxAge'])) {
$rsp->header('Access-Control-Max-Age', $this->settings['maxAge']);
$rsp->headers->set('Access-Control-Max-Age', $this->settings['maxAge']);
}
}

protected function setAllowCredentials($req, $rsp) {
if (isset($this->settings['allowCredentials']) && $this->settings['allowCredentials'] === True) {
$rsp->header('Access-Control-Allow-Credentials', 'true');
$rsp->headers->set('Access-Control-Allow-Credentials', 'true');
}
}

Expand All @@ -50,8 +48,8 @@ protected function setAllowMethods($req, $rsp) {
if (is_array($allowMethods)) {
$allowMethods = implode(", ", $allowMethods);
}
$rsp->header('Access-Control-Allow-Methods', $allowMethods);

$rsp->headers->set('Access-Control-Allow-Methods', $allowMethods);
}
}

Expand All @@ -67,7 +65,7 @@ protected function setAllowHeaders($req, $rsp) {
}

if (isset($allowHeaders)) {
$rsp->header('Access-Control-Allow-Headers', $allowHeaders);
$rsp->headers->set('Access-Control-Allow-Headers', $allowHeaders);
}
}

Expand Down