Skip to content

Commit

Permalink
Merge branch 'PHP-5.4' into PHP-5.5
Browse files Browse the repository at this point in the history
* PHP-5.4:
  Handle CLI server request headers case insensitively.
  5.4.21 now

Conflicts:
	configure.in
	main/php_version.h
  • Loading branch information
LawnGnome committed Sep 9, 2013
2 parents b54b6e3 + 3c3b2b5 commit 8b62702
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2013, PHP 5.5.5

- CLI server:
. Fixed bug #65633 (built-in server treat some http headers as
case-sensitive). (Adam)

?? ??? 2013, PHP 5.5.4

- Core:
Expand Down
17 changes: 7 additions & 10 deletions sapi/cli/php_cli_server.c
Expand Up @@ -412,7 +412,7 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
{
{
char **val;
if (SUCCESS == zend_hash_find(&client->request.headers, "Host", sizeof("Host"), (void**)&val)) {
if (SUCCESS == zend_hash_find(&client->request.headers, "host", sizeof("host"), (void**)&val)) {
smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent);
smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent);
smart_str_appends_ex(buffer, *val, persistent);
Expand Down Expand Up @@ -568,7 +568,7 @@ static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */
{
php_cli_server_client *client = SG(server_context);
char **val;
if (FAILURE == zend_hash_find(&client->request.headers, "Cookie", sizeof("Cookie"), (void**)&val)) {
if (FAILURE == zend_hash_find(&client->request.headers, "cookie", sizeof("cookie"), (void**)&val)) {
return NULL;
}
return *val;
Expand Down Expand Up @@ -1566,12 +1566,9 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p
return 1;
}
{
char *header_name = client->current_header_name;
size_t header_name_len = client->current_header_name_len;
char c = header_name[header_name_len];
header_name[header_name_len] = '\0';
zend_hash_add(&client->request.headers, header_name, header_name_len + 1, &value, sizeof(char *), NULL);
header_name[header_name_len] = c;
char *header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len);
zend_hash_add(&client->request.headers, header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL);
efree(header_name);
}

if (client->current_header_name_allocated) {
Expand Down Expand Up @@ -1729,7 +1726,7 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli
request_info->post_data = client->request.content;
request_info->content_length = request_info->post_data_length = client->request.content_len;
request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL;
if (SUCCESS == zend_hash_find(&client->request.headers, "Content-Type", sizeof("Content-Type"), (void**)&val)) {
if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) {
request_info->content_type = *val;
}
} /* }}} */
Expand Down Expand Up @@ -1967,7 +1964,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */
char **auth;
php_cli_server_client_populate_request_info(client, &SG(request_info));
if (SUCCESS == zend_hash_find(&client->request.headers, "Authorization", sizeof("Authorization"), (void**)&auth)) {
if (SUCCESS == zend_hash_find(&client->request.headers, "authorization", sizeof("authorization"), (void**)&auth)) {
php_handle_auth_data(*auth TSRMLS_CC);
}
SG(sapi_headers).http_response_code = 200;
Expand Down
48 changes: 48 additions & 0 deletions sapi/cli/tests/bug65633.phpt
@@ -0,0 +1,48 @@
--TEST--
Bug #65633 (built-in server treat some http headers as case-sensitive)
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
include "php_cli_server.inc";
php_cli_server_start(<<<'PHP'
var_dump($_COOKIE, $_SERVER['HTTP_FOO']);
PHP
);

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
cookie: foo=bar
foo: bar
HEADER
)) {
while (!feof($fp)) {
echo fgets($fp);
}
}

fclose($fp);
?>
--EXPECTF--
HTTP/1.1 200 OK
Connection: close
X-Powered-By: %s
Content-type: text/html

array(1) {
["foo"]=>
string(3) "bar"
}
string(3) "bar"

0 comments on commit 8b62702

Please sign in to comment.