|
|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-namespace App\Common\Protocols;
|
|
|
+namespace App\Common\Protocols\Http;
|
|
|
|
|
|
/**
|
|
|
* 判断http协议的数据包是否完整
|
|
|
@@ -145,6 +145,12 @@ function http_start($http_string, $SERVER = array())
|
|
|
case 'referer':
|
|
|
$_SERVER['HTTP_REFERER'] = $value;
|
|
|
break;
|
|
|
+ case 'if-modified-since':
|
|
|
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] = $value;
|
|
|
+ break;
|
|
|
+ case 'if-none-match':
|
|
|
+ $_SERVER['HTTP_IF_NONE_MATCH'] = $value;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -252,6 +258,12 @@ function header($content, $replace = true, $http_response_code = 0)
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if(isset(HttpCache::$codes[$http_response_code]))
|
|
|
+ {
|
|
|
+ HttpCache::$header['Http-Code'] = 'HTTP/1.1 ' . HttpCache::$codes[$http_response_code];
|
|
|
+ }
|
|
|
+
|
|
|
if($key == 'Set-Cookie')
|
|
|
{
|
|
|
HttpCache::$header[$key][] = $content;
|
|
|
@@ -262,7 +274,7 @@ function header($content, $replace = true, $http_response_code = 0)
|
|
|
}
|
|
|
if('location' == strtolower($key))
|
|
|
{
|
|
|
- header("HTTP/1.1 302 Moved Temporarily");
|
|
|
+ header('HTTP/1.1 302 Moved Temporarily');
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -365,7 +377,7 @@ function session_write_close()
|
|
|
{
|
|
|
return \session_write_close();
|
|
|
}
|
|
|
- if(HttpCache::$instance->sessionStarted && !empty($_SESSION))
|
|
|
+ if(!empty(HttpCache::$instance->sessionStarted) && !empty($_SESSION))
|
|
|
{
|
|
|
$session_str = session_encode();
|
|
|
if($session_str && HttpCache::$instance->sessionFile)
|
|
|
@@ -400,6 +412,51 @@ function jump_exit($msg = '')
|
|
|
*/
|
|
|
class HttpCache
|
|
|
{
|
|
|
+ public static $codes = array(
|
|
|
+ 100 => 'Continue',
|
|
|
+ 101 => 'Switching Protocols',
|
|
|
+ 200 => 'OK',
|
|
|
+ 201 => 'Created',
|
|
|
+ 202 => 'Accepted',
|
|
|
+ 203 => 'Non-Authoritative Information',
|
|
|
+ 204 => 'No Content',
|
|
|
+ 205 => 'Reset Content',
|
|
|
+ 206 => 'Partial Content',
|
|
|
+ 300 => 'Multiple Choices',
|
|
|
+ 301 => 'Moved Permanently',
|
|
|
+ 302 => 'Found',
|
|
|
+ 303 => 'See Other',
|
|
|
+ 304 => 'Not Modified',
|
|
|
+ 305 => 'Use Proxy',
|
|
|
+ 306 => '(Unused)',
|
|
|
+ 307 => 'Temporary Redirect',
|
|
|
+ 400 => 'Bad Request',
|
|
|
+ 401 => 'Unauthorized',
|
|
|
+ 402 => 'Payment Required',
|
|
|
+ 403 => 'Forbidden',
|
|
|
+ 404 => 'Not Found',
|
|
|
+ 405 => 'Method Not Allowed',
|
|
|
+ 406 => 'Not Acceptable',
|
|
|
+ 407 => 'Proxy Authentication Required',
|
|
|
+ 408 => 'Request Timeout',
|
|
|
+ 409 => 'Conflict',
|
|
|
+ 410 => 'Gone',
|
|
|
+ 411 => 'Length Required',
|
|
|
+ 412 => 'Precondition Failed',
|
|
|
+ 413 => 'Request Entity Too Large',
|
|
|
+ 414 => 'Request-URI Too Long',
|
|
|
+ 415 => 'Unsupported Media Type',
|
|
|
+ 416 => 'Requested Range Not Satisfiable',
|
|
|
+ 417 => 'Expectation Failed',
|
|
|
+ 422 => 'Unprocessable Entity',
|
|
|
+ 423 => 'Locked',
|
|
|
+ 500 => 'Internal Server Error',
|
|
|
+ 501 => 'Not Implemented',
|
|
|
+ 502 => 'Bad Gateway',
|
|
|
+ 503 => 'Service Unavailable',
|
|
|
+ 504 => 'Gateway Timeout',
|
|
|
+ 505 => 'HTTP Version Not Supported',
|
|
|
+ );
|
|
|
public static $instance = null;
|
|
|
public static $header = array();
|
|
|
public static $sessionPath = '';
|