示例#1
0
 public static function request_headers()
 {
     if (function_exists("apache_request_headers")) {
         return new HTTP_Header(apache_request_headers());
     } elseif (extension_loaded("http")) {
         $headers = version_compare(phpversion("http"), "2.0.0", ">=") ? \http\Env::getRequestHeader() : http_get_request_headers();
         return new HTTP_Header($headers);
     }
     $headers = array();
     if (!empty($_SERVER["CONTENT_TYPE"])) {
         $headers["content-type"] = $_SERVER["CONTENT_TYPE"];
     }
     if (!empty($_SERVER["CONTENT_LENGTH"])) {
         $headers["content-length"] = $_SERVER["CONTENT_LENGTH"];
     }
     foreach ($_SERVER as $key => $value) {
         if (strpos($key, "HTTP_") !== 0) {
             continue;
         }
         $headers[str_replace("_", "-", substr($key, 5))] = $value;
     }
     return new HTTP_Header($headers);
 }
示例#2
0
 /**
  * Format an error as HTML
  * @param string $title
  * @param string $message
  * @param int $code
  * @param string $trace
  * @param array $title_tag
  * @param array $message_tag
  * @param array $trace_tag
  * @return string
  */
 public static function htmlError($title, $message, $code, $trace = null, array $title_tag = ["h1"], array $message_tag = ["p"], array $trace_tag = ["pre", "style='font-size:smaller;overflow-x:scroll'"])
 {
     HTTP::setResponseCode($code);
     $html = sprintf("<%s>%s</%s>\n<%s>%s</%s>\n", implode(" ", $title_tag), $title, $title_tag[0], implode(" ", $message_tag), $message, $message_tag[0]);
     if ($trace_tag) {
         if (!isset($trace)) {
             ob_start();
             debug_print_backtrace();
             $trace = ob_get_clean();
         }
         if (!empty($trace)) {
             $html .= sprintf("<%s>%s</%s>\n", implode(" ", $trace_tag), $trace, $trace_tag[0]);
         }
     }
     return $html;
 }
示例#3
0
 /**
  * @param string $key
  * @return mixed
  */
 protected function getValue($key)
 {
     return Env::getRequestHeader($key);
 }
 /**
  * Parses the the HTTP request headers and returns an array containing
  * key value pairs. This method is slow, but provides an accurate
  * representation of the HTTP request.
  *
  *      // Get http headers into the request
  *      $request->headers = HTTP::request_headers();
  *
  * @return  HTTP_Header
  */
 public static function request_headers()
 {
     // If running on apache server
     if (function_exists('apache_request_headers')) {
         // Return the much faster method
         return new HTTP_Header(apache_request_headers());
     } elseif (extension_loaded('http')) {
         // Return the much faster method
         $headers = version_compare(phpversion('http'), '2.0.0', '>=') ? \http\Env::getRequestHeader() : http_get_request_headers();
         return new HTTP_Header($headers);
     }
     // Setup the output
     $headers = array();
     // Parse the content type
     if (!empty($_SERVER['CONTENT_TYPE'])) {
         $headers['content-type'] = $_SERVER['CONTENT_TYPE'];
     }
     // Parse the content length
     if (!empty($_SERVER['CONTENT_LENGTH'])) {
         $headers['content-length'] = $_SERVER['CONTENT_LENGTH'];
     }
     foreach ($_SERVER as $key => $value) {
         // If there is no HTTP header here, skip
         if (strpos($key, 'HTTP_') !== 0) {
             continue;
         }
         // This is a dirty hack to ensure HTTP_X_FOO_BAR becomes X-FOO-BAR
         $headers[str_replace('_', '-', substr($key, 5))] = $value;
     }
     return new HTTP_Header($headers);
 }