Skip to content

Commit 8503a2a

Browse files
committed
Instead of sending headers on his own, the module append them to the headers response collection on "afterPrepare"
1 parent bc9bb99 commit 8503a2a

7 files changed

+28
-13
lines changed

src/components/Response.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
/**
77
* Class Response
8+
*
89
* ```php
910
* [
1011
* 'components' => [
1112
* 'response' => [
1213
* 'class' => 'bicf\securityheaders\Response',
13-
* 'on afterPrepare' => ['bicf\securityheaders\Response','modulesInit'],
14-
* 'on afterSend' => ['bicf\securityheaders\Response','modulesSendHeaders'],
14+
* 'on afterPrepare' => ['bicf\securityheaders\Response','addSecurityHeaders'],
1515
* 'modules' => [
1616
* 'XContentTypeOptions'=>[
1717
* 'class' => 'bicf\securityheaders\modules\HeaderXContentTypeOptions',
@@ -93,11 +93,11 @@ public function init()
9393
/**
9494
*
9595
*/
96-
public static function modulesSendHeaders($event)
96+
public static function addSecurityHeaders($event)
9797
{
9898
/** @var $event->sender \bicf\securityheaders\components\Response */
9999
foreach ($event->sender->modules as $module){
100-
$module->send();
100+
$module->run();
101101
}
102102
}
103103
}

src/modules/HeaderAccessControlAllowMethods.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ public function init()
1818
}
1919
}
2020

21-
public function send()
21+
public function run()
2222
{
2323
if(!$this->enabled){
2424
return;
2525
}
26-
\Yii::$app->response->headers->set('Access-Control-Allow-Methods',$this->value);
26+
// new Header
27+
\Yii::$app->response->headers->add('Access-Control-Allow-Methods',$this->value);
2728
}
2829
}

src/modules/HeaderAccessControlAllowOrigin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class HeaderAccessControlAllowOrigin extends HeaderModuleBase
1010
{
1111
public $value;
1212

13-
public function send()
13+
public function run()
1414
{
1515
if(!$this->enabled){
1616
return;
1717
}
1818
if($this->value === null){
1919
return;
2020
}
21-
\Yii::$app->response->headers->set('Access-Control-Allow-Origin',$this->value);
21+
\Yii::$app->response->headers->add('Access-Control-Allow-Origin',$this->value);
2222
}
2323
}

src/modules/HeaderContentSecurityPolicyBase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class HeaderContentSecurityPolicyBase extends HeaderModuleBase
3636
/**
3737
* add the security header
3838
*/
39-
public function send(){
39+
public function run(){
4040
if(!$this->enabled){
4141
return;
4242
}
@@ -50,7 +50,7 @@ public function send(){
5050
$value .="$sep$k $v";
5151
$sep ="; ";
5252
}
53-
\Yii::$app->response->headers->set($this->headerName,$value);
53+
\Yii::$app->response->headers->add($this->headerName,$value);
5454
}
5555

5656
public function injectBehavior(Response $response)

src/modules/HeaderModuleInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ interface HeaderModuleInterface
1515
{
1616
public function init();
1717
public function injectBehavior(Response $response);
18-
public function send();
18+
public function run();
1919
}

src/modules/HeaderXContentTypeOptions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public function init()
2020
}
2121

2222

23-
public function send()
23+
public function run()
2424
{
2525
if(!$this->enabled){
2626
return;
2727
}
28-
\Yii::$app->response->headers->set('X-Content-Type-Options',$this->value);
28+
\Yii::$app->response->headers->add('X-Content-Type-Options',$this->value);
2929
}
3030
}

tests/tp.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
for($three=1;$three<2000;$three++){
4+
for($two=1;$two<2000;$two++){
5+
$gtwo = gmp_pow("2",$two);
6+
$gthree = gmp_pow("3",$three);
7+
$gnup = gmp_add(gmp_mul($gtwo,$gthree),1 );
8+
$gndown = gmp_sub(gmp_mul($gtwo,$gthree),"1" );
9+
if(gmp_prob_prime($gnup) && gmp_prob_prime($gndown)){
10+
printf("%s ## %s \n",gmp_strval($gndown),gmp_strval($gnup));
11+
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)