@@ -20,6 +20,49 @@ public function __construct(array $options = null)
2020 }
2121 }
2222
23+ public function send ($ replace = false )
24+ {
25+ ksort ($ this ->headers , \SORT_STRING );
26+ foreach ($ this ->headers as $ value ) {
27+ $ value ->send ($ replace );
28+ }
29+ }
30+
31+ public function getHeaders ()
32+ {
33+ return $ this ->headers ;
34+ }
35+
36+ public function toArray ()
37+ {
38+ $ headers = array ();
39+ foreach ($ this ->headers as $ value ) {
40+ $ headers = $ value ->getHeader ();
41+ }
42+ asort ($ headers , \SORT_STRING );
43+ return $ headers ;
44+ }
45+
46+ public function toString ()
47+ {
48+ $ string = '' ;
49+ $ headers = $ this ->toArray ();
50+ foreach ($ headers as $ header ) {
51+ $ string .= sprintf ('%s\r\n ' , $ header );
52+ }
53+ return $ string ;
54+ }
55+
56+ public function __toString ()
57+ {
58+ return $ this ->toString ();
59+ }
60+
61+ public function count ()
62+ {
63+ return count ($ this ->headers );
64+ }
65+
2366 public function setOptions (array $ options )
2467 {
2568 foreach ($ options as $ key => $ value ) {
@@ -33,8 +76,15 @@ public function setOption($key, $options)
3376 case 'strict_transport_security ' :
3477 case 'sts ' :
3578 try {
36- $ this ->headers ['strict_transport_security ' ]
37- = new Header \StrictTransportSecurity ($ options );
79+ if (!isset ($ this ->headers ['strict_transport_security ' ])) {
80+ $ this ->headers ['strict_transport_security ' ]
81+ = new Header \StrictTransportSecurity ($ options );
82+ } else {
83+ foreach ($ options as $ key => $ value ) {
84+ $ this ->headers ['strict_transport_security ' ]
85+ ->setOption ($ key , $ value );
86+ }
87+ }
3888 } catch (\Exception $ e ) {
3989 throw $ e ;
4090 }
@@ -43,8 +93,15 @@ public function setOption($key, $options)
4393 case 'csrf_token ' :
4494 case 'csrf ' :
4595 try {
46- $ this ->headers ['x_csrftoken ' ]
47- = new Header \CsrfToken ($ options );
96+ if (!isset ($ this ->headers ['csrf_token ' ])) {
97+ $ this ->headers ['csrf_token ' ]
98+ = new Header \CsrfToken ($ options );
99+ } else {
100+ foreach ($ options as $ key => $ value ) {
101+ $ this ->headers ['csrf_token ' ]
102+ ->setOption ($ key , $ value );
103+ }
104+ }
48105 } catch (\Exception $ e ) {
49106 throw $ e ;
50107 }
@@ -60,52 +117,40 @@ public function setOption($key, $options)
60117
61118 public function getOption ($ key )
62119 {
63- if (isset ($ this ->options [$ key ])) {
64- return $ this ->options [$ key ];
65- }
66- }
67-
68- public function send ($ replace = false )
69- {
70- ksort ($ this ->headers , \SORT_STRING );
71- foreach ($ this ->headers as $ value ) {
72- $ value ->send ($ replace );
73- }
74- }
75-
76- public function getHeaders ()
77- {
78- return $ this ->headers ;
79- }
120+ switch ($ key ) {
121+ case 'strict_transport_security ' :
122+ case 'sts ' :
123+ return $ this ->headers ['strict_transport_security ' ]->getOptions ();
124+ break ;
80125
81- public function toArray ()
82- {
83- $ headers = array ();
84- foreach ($ this ->headers as $ value ) {
85- $ headers = $ value ->getHeader ();
126+ case 'csrf_token ' :
127+ case 'csrf ' :
128+ return $ this ->headers ['csrf_token ' ]->getOptions ();
129+ break ;
130+
131+ default :
132+ return null ;
133+ break ;
86134 }
87- asort ($ headers , \SORT_STRING );
88- return $ headers ;
89135 }
90136
91- public function toString ()
137+ public function getOptions ()
92138 {
93- $ string = '' ;
94- $ headers = $ this ->toArray ( );
95- foreach ($ headers as $ header ) {
96- $ string .= sprintf ( ' %s\r\n ' , $ header );
139+ $ return = array () ;
140+ ksort ( $ this ->headers , \ SORT_STRING );
141+ foreach ($ this -> headers as $ key => $ value ) {
142+ $ return [ $ key ] = $ value -> getOptions ( );
97143 }
98- return $ string ;
144+ return $ return ;
99145 }
100146
101- public function __toString ( )
147+ public function addHeader ( Header \ HeaderInterface $ header )
102148 {
103- return $ this ->toString ();
104- }
105-
106- public function count ()
107- {
108- return count ($ this ->headers );
149+ $ class = get_class ($ header );
150+ $ parts = explode ('\\' , $ class );
151+ $ name = strtolower (array_shift ($ parts ));
152+ $ this ->headers [$ name ] = $ header ;
153+ return $ this ;
109154 }
110155
111156}
0 commit comments