Add SERVER_PROTOCOL variable to $_SERVER. Patch by kuzuha. Thanks.

This commit is contained in:
Moriyoshi Koizumi 2011-10-21 05:24:30 +00:00
parent 465cb32c4c
commit 2cf34bc9fc
2 changed files with 77 additions and 0 deletions

View File

@ -571,6 +571,12 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC)
sapi_cli_server_register_variable(track_vars_array, "SERVER_SOFTWARE", tmp TSRMLS_CC);
efree(tmp);
}
{
char *tmp;
spprintf(&tmp, 0, "HTTP/%d.%d", client->request.protocol_version / 100, client->request.protocol_version % 100);
sapi_cli_server_register_variable(track_vars_array, "SERVER_PROTOCOL", tmp TSRMLS_CC);
efree(tmp);
}
sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri TSRMLS_CC);
sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method TSRMLS_CC);
sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC);

View File

@ -0,0 +1,71 @@
--TEST--
SERVER_PROTOCOL header availability
--SKIPIF--
<?php
include "skipif.inc";
if (substr(PHP_OS, 0, 3) == 'WIN') {
die ("skip not for Windows");
}
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start('var_dump($_SERVER["SERVER_PROTOCOL"]);');
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
$port = intval($port)?:80;
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
if(fwrite($fp, <<<HEADER
GET / HTTP/1.1
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}
fclose($fp);
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}
if(fwrite($fp, <<<HEADER
GET / HTTP/1.0
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}
fclose($fp);
?>
--EXPECTF--
HTTP/1.1 200 OK
Host: %s
Connection: closed
X-Powered-By: PHP/%s-dev
Content-type: text/html
string(8) "HTTP/1.1"
HTTP/1.0 200 OK
Host: %s
Connection: closed
X-Powered-By: PHP/%s-dev
Content-type: text/html
string(8) "HTTP/1.0"