コード例 #1
0
ファイル: http.php プロジェクト: gilyaev/framework-bench
 /**
  * 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
         return new HTTP_Header(http_get_request_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(array('HTTP_', '_'), array('', '-'), $key)] = $value;
     }
     return new HTTP_Header($headers);
 }
コード例 #2
0
/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}
コード例 #3
0
ファイル: Yii2RequestPanel.php プロジェクト: Orlac/yii2-debug
 public function save()
 {
     if (function_exists('apache_request_headers')) {
         $requestHeaders = apache_request_headers();
     } elseif (function_exists('http_get_request_headers')) {
         $requestHeaders = http_get_request_headers();
     } else {
         $requestHeaders = array();
     }
     $responseHeaders = array();
     foreach (headers_list() as $header) {
         if (($pos = strpos($header, ':')) !== false) {
             $name = substr($header, 0, $pos);
             $value = trim(substr($header, $pos + 1));
             if (isset($responseHeaders[$name])) {
                 if (!is_array($responseHeaders[$name])) {
                     $responseHeaders[$name] = array($responseHeaders[$name], $value);
                 } else {
                     $responseHeaders[$name][] = $value;
                 }
             } else {
                 $responseHeaders[$name] = $value;
             }
         } else {
             $responseHeaders[] = $header;
         }
     }
     $route = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest());
     $action = null;
     $actionParams = array();
     if (($ca = @Yii::app()->createController($route)) !== null) {
         /* @var CController $controller */
         /* @var string $actionID */
         list($controller, $actionID) = $ca;
         if (!$actionID) {
             $actionID = $controller->defaultAction;
         }
         if (($a = $controller->createAction($actionID)) !== null) {
             if ($a instanceof CInlineAction) {
                 $action = get_class($controller) . '::action' . ucfirst($actionID) . '()';
             } else {
                 $action = get_class($a) . '::run()';
             }
         }
         $actionParams = $controller->actionParams;
     }
     $flashes = array();
     $user = Yii::app()->getComponent('user', false);
     if ($user instanceof CWebUser) {
         $flashes = $user->getFlashes(false);
     }
     return array('flashes' => $flashes, 'statusCode' => $this->getStatusCode(), 'requestHeaders' => $requestHeaders, 'responseHeaders' => $responseHeaders, 'route' => $route, 'action' => $action, 'actionParams' => $actionParams, 'SERVER' => empty($_SERVER) ? array() : $_SERVER, 'GET' => empty($_GET) ? array() : $_GET, 'POST' => empty($_POST) ? array() : $_POST, 'COOKIE' => empty($_COOKIE) ? array() : $_COOKIE, 'FILES' => empty($_FILES) ? array() : $_FILES, 'SESSION' => empty($_SESSION) ? array() : $_SESSION);
 }
コード例 #4
0
ファイル: Request.php プロジェクト: ybluesky/h2o
 /**
  * 返回header头信息
  */
 public function getHeaders()
 {
     if (function_exists('getallheaders')) {
         $headers = getallheaders();
     } elseif (function_exists('http_get_request_headers')) {
         $headers = http_get_request_headers();
     } else {
         $headers = [];
         foreach ($_SERVER as $name => $value) {
             if (substr($name, 0, 5) == 'HTTP_') {
                 $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
             }
         }
     }
     return $headers;
 }
コード例 #5
0
 private function parseHeaders()
 {
     $headers = null;
     if (function_exists('http_get_request_headers')) {
         //Try to use pcre_http library if it exists
         $headers = http_get_request_headers();
     } else {
         if (function_exists('apache_request_headers')) {
             //If not: try to use apache specific headers
             $headers = apache_request_headers();
         } else {
             //If not: not supported - empty headers
             $headers = array();
         }
     }
     $this->headers = $headers;
 }
コード例 #6
0
ファイル: Helper.php プロジェクト: shanehill00/webdfs
 public static function getParams()
 {
     $params = array('fileName' => '', 'pathHash' => '', 'name' => '', 'action' => '', 'replica' => 0, 'position' => null, 'configIndex' => 0, 'moveConfigIndex' => 0, 'moveContext' => WebDFS::MOVE_CONTEXT_START, 'getContext' => '', 'propagateDelete' => 1);
     // need to create the path info if nothing exists
     if (!isset($_SERVER['PATH_INFO']) && isset($_SERVER['REDIRECT_URL'])) {
         $_SERVER['PATH_INFO'] = preg_replace('/^.*?\\/([^\\/]+)$/', '\\1', $_SERVER['REDIRECT_URL']);
     }
     if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !== '') {
         $params['action'] = strtolower($_SERVER['REQUEST_METHOD']);
         $params['name'] = trim($_SERVER['PATH_INFO'], '/');
         $params['name'] = str_replace(array('\\0'), "", $params['name']);
         $params['fileName'] = basename($params['name']);
         // hash the path info
         $params['pathHash'] = self::getPathHash($params['name']);
         $headers = http_get_request_headers();
         if (isset($headers[WebDFS::HEADER_REPLICA])) {
             $params['replica'] = (int) $headers[WebDFS::HEADER_REPLICA];
         }
         if (isset($headers[WebDFS::HEADER_POSITION])) {
             $params['position'] = (int) $headers[WebDFS::HEADER_POSITION];
         }
         if (isset($headers[WebDFS::HEADER_CONFIG_INDEX])) {
             $params['configIndex'] = (int) $headers[WebDFS::HEADER_CONFIG_INDEX];
         }
         if (isset($headers[WebDFS::HEADER_MOVE_CONTEXT])) {
             $params['moveContext'] = strtolower($headers[WebDFS::HEADER_MOVE_CONTEXT]);
         }
         if (isset($headers[WebDFS::HEADER_MOVE_CONFIG_INDEX])) {
             $params['moveConfigIndex'] = (int) $headers[WebDFS::HEADER_MOVE_CONFIG_INDEX];
         }
         if (isset($headers[WebDFS::HEADER_GET_CONTEXT])) {
             $params['getContext'] = $headers[WebDFS::HEADER_GET_CONTEXT];
         }
         if (isset($headers[WebDFS::HEADER_CONTENT_LENGTH])) {
             $params['contentLength'] = (int) $headers[WebDFS::HEADER_CONTENT_LENGTH];
         }
         if (isset($headers[WebDFS::HEADER_PROPAGATE_DELETE])) {
             $params['propagateDelete'] = (int) $headers[WebDFS::HEADER_PROPAGATE_DELETE];
         }
         if (isset($headers[WebDFS::HEADER_FORCE_DELETE])) {
             $params['forceDelete'] = (int) $headers[WebDFS::HEADER_FORCE_DELETE];
         }
     }
     return $params;
 }
コード例 #7
0
ファイル: Request.php プロジェクト: otherjohn/govid
 protected function readHeaders()
 {
     if (function_exists('apache_request_headers')) {
         // @codeCoverageIgnoreStart
         $headers = apache_request_headers();
     } elseif (function_exists('http_get_request_headers')) {
         $headers = http_get_request_headers();
     } else {
         // @codeCoverageIgnoreEnd
         $headers = array();
         foreach ($this->server() as $name => $value) {
             if (substr($name, 0, 5) == 'HTTP_') {
                 // HTTP_FOO_BAR becomes FOO-BAR
                 $name = str_replace(array('HTTP_', '_'), array('', '-'), $name);
                 $headers[$name] = $value;
             }
         }
     }
     return $this->normalizeHeaders($headers);
 }
コード例 #8
0
ファイル: JzRequest.php プロジェクト: chenyongze/yii2-swoole
 /**
  * Returns the header collection.
  * The header collection contains incoming HTTP headers.
  * @return HeaderCollection the header collection
  */
 public function getHeaders()
 {
     if ($this->_headers === null) {
         $this->_headers = new HeaderCollection();
         if (function_exists('getallheaders')) {
             $headers = getallheaders();
         } elseif (function_exists('http_get_request_headers')) {
             $headers = http_get_request_headers();
         } else {
             foreach ($_SERVER as $name => $value) {
                 if (strncmp($name, 'HTTP_', 5) === 0) {
                     $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                     $this->_headers->add($name, $value);
                 }
             }
             return $this->_headers;
         }
         foreach ($headers as $name => $value) {
             $this->_headers->add($name, $value);
         }
     }
     return $this->_headers;
 }
コード例 #9
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);
 }
コード例 #10
0
ファイル: Client.php プロジェクト: inhere/php-librarys
 /**
  * @return array|false|null
  */
 public function getHeaders()
 {
     if ($this->_headers === null) {
         if (function_exists('getallheaders')) {
             $this->_headers = getallheaders();
         } elseif (function_exists('http_get_request_headers')) {
             $this->_headers = http_get_request_headers();
         } else {
             foreach ($_SERVER as $name => $value) {
                 if ($name = $this->_nameConver($name)) {
                     $this->_headers[$name] = $value;
                 }
             }
         }
     }
     return $this->_headers;
 }
コード例 #11
0
ファイル: Input.php プロジェクト: jesusslim/partini
 public function header($key = null)
 {
     $headers = http_get_request_headers();
     return is_null($key) ? $headers : $headers[$key];
 }
コード例 #12
0
ファイル: Request.php プロジェクト: phpf/micro
 /**
  * Build the request using the (super) global variables.
  * 
  * @uses http_get_request_headers()
  * @uses http_get_request_body()
  * 
  * @return \Phpf\Request
  */
 public static function createFromGlobals()
 {
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
     $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
     // Set request path
     if (isset($_SERVER['PATH_INFO'])) {
         $uri = urldecode($_SERVER['PATH_INFO']);
     } else {
         $uri = urldecode($_SERVER['REQUEST_URI']);
         // Remove query string from path
         if (false !== ($qpos = strpos($uri, '?'))) {
             $uri = substr($uri, 0, $qpos);
         }
     }
     $headers = http_get_request_headers();
     // Set request body data as per RFC 3875 4.2, 4.3
     if ('HEAD' === $method || 'POST' === $method && empty($headers['content-length'])) {
         // HEAD requests have no body - ha!
         // POST requests must have content-length
         $data = array();
     } else {
         if ('POST' === $method && isset($headers['content-type']) && 'multipart/form-data' === $headers['content-type']) {
             // Use php://input except for POST with enctype="multipart/form-data"
             // @see {@link http://us3.php.net/manual/en/wrappers.php.php}
             $data = $_POST;
         } else {
             parse_str(http_get_request_body(), $data);
         }
     }
     return new static($method, $uri, $query, $headers, $data, $_COOKIE, $_FILES);
 }
コード例 #13
0
<?php

$request_headers = http_get_request_headers();
$dataType = isset($request_headers["X-File-Type"]) ? $request_headers["X-File-Type"] : "image/jpg";
echo "data:" . $dataType . ";base64," . base64_encode(http_get_request_body());
コード例 #14
0
ファイル: PhpTransport.php プロジェクト: AndreyErikin/JsonRpc
 public function getRequestHeaders()
 {
     if ($this->_headers === null) {
         $this->_headers = [];
         if (function_exists('getallheaders')) {
             foreach (getallheaders() as $name => $value) {
                 $this->_headers[$name] = $value;
             }
         } elseif (function_exists('http_get_request_headers')) {
             foreach (http_get_request_headers() as $name => $value) {
                 $this->_headers[$name] = $value;
             }
         } else {
             foreach ($_SERVER as $name => $value) {
                 if (strncmp($name, 'HTTP_', 5) === 0) {
                     $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                     $this->_headers[$name] = $value;
                 }
             }
         }
     }
     return $this->_headers;
 }
コード例 #15
0
ファイル: AutoExpires.php プロジェクト: admpub/MicroPHP
 public static function getHeaders()
 {
     $headers = array();
     if (function_exists('getallheaders')) {
         $headers = getallheaders();
     } elseif (function_exists('apache_request_headers')) {
         $headers = apache_request_headers();
     } elseif (function_exists('http_get_request_headers')) {
         $headers = http_get_request_headers();
     }
     foreach ($headers as $key => $value) {
         $key = 'HTTP_' . strtoupper(str_replace('-', '_', $key));
         if (!isset($_SERVER[$key])) {
             $_SERVER[$key] = $value;
         }
     }
     return $headers;
 }
コード例 #16
0
ファイル: index.php プロジェクト: plus3network/PHPHelpers
    option('env', ENV_DEVELOPMENT);
    option('debug', true);
    option('session', 'Yummy_Plus3_Session_Cookie');
    // true, false or the name of your session
    option('encoding', 'utf-8');
}
// END function configure()
# the index request
dispatch('/', function () {
    return 'hello world';
});
dispatch('/phpinfo', function () {
    phpinfo();
    return;
});
$echo = function () {
    setcookie('example', 'test');
    $response = array();
    foreach ($GLOBALS as $key => $data) {
        if ($key != 'GLOBALS') {
            $response[$key] = $data;
        }
    }
    $response['_HEADERS'] = http_get_request_headers();
    return json($response);
};
dispatch_get('/echo', $echo);
dispatch_post('/echo', $echo);
dispatch_put('/echo', $echo);
dispatch_delete('/echo', $echo);
run();
コード例 #17
0
 public function getHeaders()
 {
     return http_get_request_headers();
 }
コード例 #18
0
ファイル: Http.php プロジェクト: tourze/base
 /**
  * 解析请求,并读取其中的HEADER信息
  *
  * @return array
  */
 public static function requestHeaders()
 {
     Base::getLog()->debug(__METHOD__ . ' parse requested headers');
     // apache服务器
     if (function_exists('apache_request_headers')) {
         return apache_request_headers();
     } elseif (extension_loaded('http')) {
         return http_get_request_headers();
     }
     $headers = [];
     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) {
         // 跳过非HTTP开头的值
         if (strpos($key, 'HTTP_') !== 0) {
             continue;
         }
         $key = str_replace(['HTTP_', '_'], ['', '-'], $key);
         $key = strtolower($key);
         $headers[$key] = $value;
     }
     return $headers;
 }