moriyoshi                                Fri, 21 Oct 2011 05:24:30 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=318283

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

Changed paths:
    U   php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
    A   php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_008.phpt
    U   php/php-src/trunk/sapi/cli/php_cli_server.c
    A   php/php-src/trunk/sapi/cli/tests/php_cli_server_008.phpt

Modified: php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-10-21 
01:39:45 UTC (rev 318282)
+++ php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-10-21 
05:24:30 UTC (rev 318283)
@@ -571,6 +571,12 @@
                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);

Added: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_008.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_008.phpt         
                (rev 0)
+++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_008.phpt 
2011-10-21 05:24:30 UTC (rev 318283)
@@ -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"

Modified: php/php-src/trunk/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/trunk/sapi/cli/php_cli_server.c 2011-10-21 01:39:45 UTC (rev 
318282)
+++ php/php-src/trunk/sapi/cli/php_cli_server.c 2011-10-21 05:24:30 UTC (rev 
318283)
@@ -571,6 +571,12 @@
                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);

Added: php/php-src/trunk/sapi/cli/tests/php_cli_server_008.phpt
===================================================================
--- php/php-src/trunk/sapi/cli/tests/php_cli_server_008.phpt                    
        (rev 0)
+++ php/php-src/trunk/sapi/cli/tests/php_cli_server_008.phpt    2011-10-21 
05:24:30 UTC (rev 318283)
@@ -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"

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to