示例#1
0
 /**
  * Fill up the headers property with the values
  * provided by the client browser.
  *
  * @param Request $request
  */
 private static function fillCurrentHeaders(Request $request)
 {
     $headers = [];
     //Native method exists?
     if (function_exists('getallheaders')) {
         //try to use it
         if (($headers = getallheaders()) === false) {
             $headers = [];
         }
     }
     //No header captured yet? Try to get it myself
     if (empty($headers)) {
         /*
          * Based on a user note provided by joyview
          * at http://php.net/manual/en/function.getallheaders.php
          */
         foreach ($_SERVER as $key => $value) {
             if (substr($key, 0, 5) === 'HTTP_') {
                 $newKey = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
                 $headers[$newKey] = $value;
             }
         }
     }
     $request->setHeaders($headers);
 }