@@ -9,14 +9,16 @@ class Request
9
9
private $ params ;
10
10
private $ body ;
11
11
private $ headers ;
12
+ private $ highPerformance ;
12
13
13
- public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null )
14
+ public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null , bool $ highPerformance = true )
14
15
{
15
16
$ this ->parseMethod ($ method );
16
17
$ this ->parsePath ($ path );
17
18
$ this ->parseParams ($ query );
18
19
$ this ->parseHeaders ($ headers );
19
20
$ this ->parseBody ($ body );
21
+ $ this ->highPerformance = $ highPerformance ;
20
22
}
21
23
22
24
private function parseMethod (String $ method = null )
@@ -61,10 +63,12 @@ private function parseHeaders(array $headers = null)
61
63
{
62
64
if (!$ headers ) {
63
65
$ headers = array ();
64
- foreach ($ _SERVER as $ name => $ value ) {
65
- if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
66
- $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
67
- $ headers [$ key ] = $ value ;
66
+ if (!$ this ->highPerformance ) {
67
+ foreach ($ _SERVER as $ name => $ value ) {
68
+ if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
69
+ $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
70
+ $ headers [$ key ] = $ value ;
71
+ }
68
72
}
69
73
}
70
74
}
@@ -135,6 +139,12 @@ public function getHeader(String $key): String
135
139
if (isset ($ this ->headers [$ key ])) {
136
140
return $ this ->headers [$ key ];
137
141
}
142
+ if ($ this ->highPerformance ) {
143
+ $ serverKey = 'HTTP_ ' . strtoupper (str_replace ('_ ' , '- ' , $ key ));
144
+ if (isset ($ _SERVER [$ serverKey ])) {
145
+ return $ _SERVER [$ serverKey ];
146
+ }
147
+ }
138
148
return '' ;
139
149
}
140
150
0 commit comments