@@ -35,7 +35,7 @@ final class HttpRequest
3535 // all other sh1t
3636 private $ attached = array ();
3737
38- private $ headers = array () ;
38+ private $ headers = null ;
3939
4040 /**
4141 * @var HttpMethod
@@ -47,7 +47,6 @@ final class HttpRequest
4747 */
4848 private $ url = null ;
4949
50- //for CurlHttpClient if you need to send raw CURLOPT_POSTFIELDS
5150 private $ body = null ;
5251
5352 /**
@@ -74,9 +73,12 @@ public static function createFromGlobals()
7473 if (isset ($ _SESSION ))
7574 $ request ->setSession ($ _SESSION );
7675
77- foreach ($ _SERVER as $ name => $ value )
78- if (substr ($ name , 0 , 5 ) === 'HTTP_ ' )
79- $ request ->setHeaderVar (substr ($ name , 5 ), $ value );
76+ foreach ($ _SERVER as $ name => $ value ) {
77+ if (strpos ($ name , 'HTTP_ ' ) === 0 ) {
78+ $ name = str_replace ('_ ' , '- ' , substr ($ name , 5 ));
79+ $ request ->setHeaderVar ($ name , $ value );
80+ }
81+ }
8082
8183 if (
8284 $ request ->hasServerVar ('CONTENT_TYPE ' )
@@ -86,6 +88,11 @@ public static function createFromGlobals()
8688
8789 return $ request ;
8890 }
91+
92+ public function __construct ()
93+ {
94+ $ this ->headers = new HttpHeaderCollection ();
95+ }
8996
9097 public function &getGet ()
9198 {
@@ -218,7 +225,11 @@ public function &getSession()
218225 {
219226 return $ this ->session ;
220227 }
221-
228+
229+ /**
230+ * @param string $name
231+ * @return mixed
232+ */
222233 public function getSessionVar ($ name )
223234 {
224235 return $ this ->session [$ name ];
@@ -278,7 +289,11 @@ public function &getAttached()
278289 {
279290 return $ this ->attached ;
280291 }
281-
292+
293+ /**
294+ * @param string $name
295+ * @return mixed
296+ */
282297 public function getAttachedVar ($ name )
283298 {
284299 return $ this ->attached [$ name ];
@@ -306,7 +321,7 @@ public function getByType(RequestType $type)
306321
307322 public function getHeaderList ()
308323 {
309- return $ this ->headers ;
324+ return $ this ->headers -> getAll () ;
310325 }
311326
312327 public function hasHeaderVar ($ name )
@@ -316,7 +331,7 @@ public function hasHeaderVar($name)
316331
317332 public function getHeaderVar ($ name )
318333 {
319- return $ this ->headers [ $ name] ;
334+ return $ this ->headers -> get ( $ name) ;
320335 }
321336
322337 /**
@@ -333,7 +348,7 @@ public function unsetHeaderVar($name)
333348 **/
334349 public function setHeaderVar ($ name , $ var )
335350 {
336- $ this ->headers [ $ name] = $ var ;
351+ $ this ->headers -> set ( $ name, $ var) ;
337352 return $ this ;
338353 }
339354
@@ -342,7 +357,7 @@ public function setHeaderVar($name, $var)
342357 **/
343358 public function setHeaders (array $ headers )
344359 {
345- $ this ->headers = $ headers ;
360+ $ this ->headers = new HttpHeaderCollection ( $ headers) ;
346361 return $ this ;
347362 }
348363
0 commit comments