Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions ext/standard/tests/general_functions/head.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,51 @@ header() and friends
--FILE--
<?php

$v1 = headers_sent();
$v2 = headers_list();
var_dump(header("HTTP 1.0", true, 200));
$sent1 = headers_sent();
$list1 = headers_list();

var_dump($v1);
var_dump($v2);
header("HTTP 1.1", true, 200);
$list2 = headers_list();
header("Date: Mon, 25 Mar 1985 00:20:00 GMT");
$list3 = headers_list();

var_dump(header(""));
var_dump(header("", true));
var_dump(headers_sent());
var_dump(headers_list());
var_dump(header("HTTP blah"));
var_dump(header("HTTP blah", true));
var_dump(headers_sent());
var_dump(headers_list());
header_remove();
$list4 = headers_list();

var_dump(
$sent1,
$list1,
$list2,
$list3,
$list4,
);

header("Too late !!");

echo "Done\n";
?>
--EXPECTF--
NULL
bool(false)
array(0) {
array(1) {
[0]=>
string(%d) "X-Powered-By: PHP/%s"
}
array(2) {
[0]=>
string(%d) "X-Powered-By: PHP/%s"
[1]=>
string(8) "HTTP 1.1"
}
array(3) {
[0]=>
string(%d) "X-Powered-By: PHP/%s"
[1]=>
string(8) "HTTP 1.1"
[2]=>
string(35) "Date: Mon, 25 Mar 1985 00:20:00 GMT"
}

Warning: Cannot modify header information - headers already sent by (output started at %s:%d) in %s on line %d
NULL

Warning: Cannot modify header information - headers already sent by (output started at %s:%d) in %s on line %d
NULL
bool(true)
array(0) {
}

Warning: Cannot modify header information - headers already sent by (output started at %s:%d) in %s on line %d
NULL

Warning: Cannot modify header information - headers already sent by (output started at %s:%d) in %s on line %d
NULL
bool(true)
array(0) {
}
Done
8 changes: 1 addition & 7 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,6 @@ static char* sapi_cli_read_cookies(void) /* {{{ */
}
/* }}} */

static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s) /* {{{ */
{
return 0;
}
/* }}} */

static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */
{
/* We do nothing here, this function is needed to prevent that the fallback
Expand Down Expand Up @@ -430,7 +424,7 @@ static sapi_module_struct cli_sapi_module = {

php_error, /* error handler */

sapi_cli_header_handler, /* header handler */
NULL, /* header handler */
sapi_cli_send_headers, /* send headers handler */
sapi_cli_send_header, /* send header handler */

Expand Down
35 changes: 35 additions & 0 deletions sapi/cli/tests/cli_header_handler.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
CLI header(), header_remove() and headers_list()
--SKIPIF--
<?php include "skipif.inc" ?>
--INI--
expose_php=On
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the X-Powered-By header test separately and remove it by default in the others.

--FILE--
<?php
header("A: first");
header("A: second", TRUE);
$headers1 = headers_list();
header("A: third", FALSE);
$headers2 = headers_list();
header_remove("A");
$headers3 = headers_list();
print_r($headers1);
print_r($headers2);
print_r($headers3);
?>
--EXPECTF--
Array
(
[0] => X-Powered-By: %s
[1] => A: second
)
Array
(
[0] => X-Powered-By: %s
[1] => A: second
[2] => A: third
)
Array
(
[0] => X-Powered-By: %s
)
24 changes: 24 additions & 0 deletions sapi/cli/tests/cli_header_session.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
CLI session create header
--SKIPIF--
<?php include "skipif.inc"; ?>
--INI--
expose_php=On
--FILE--
<?php
session_name("foo");
session_id('bar');
session_start();

$headers = headers_list();
print_r($headers);
?>
--EXPECTF--
Array
(
[0] => X-Powered-By: %s
[1] => Set-Cookie: foo=bar; path=/
[2] => Expires: %s
[3] => Cache-Control: no-store, no-cache, must-revalidate
[4] => Pragma: no-cache
)
22 changes: 22 additions & 0 deletions sapi/cli/tests/cli_header_setcookie.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
CLI setcookie() create header
--SKIPIF--
<?php include "skipif.inc"; ?>
--INI--
expose_php=On
--FILE--
<?php
setcookie('hi', time()+3600);

setcookie('hi');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please duplicate the test with setrawcookie function


$headers = headers_list();
print_r($headers);
?>
--EXPECTF--
Array
(
[0] => X-Powered-By: %s
[1] => Set-Cookie: hi=%s
[2] => Set-Cookie: hi=deleted;%s
)
35 changes: 35 additions & 0 deletions sapi/cli/tests/cli_headers_sent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
CLI headers_sent()
--SKIPIF--
<?php include "skipif.inc" ?>
--FILE--
<?php
$sent1 = headers_sent();

fwrite(STDOUT, "Hi !!");
$sent2 = headers_sent();

ob_start();
echo "Bye !!\n";
$sent3 = headers_sent();

$out = ob_get_clean();
$sent4 = headers_sent();

echo $out;

var_dump(
$sent1,
$sent2,
$sent3,
$sent4,
headers_sent()
);
?>
--EXPECT--
Hi !!Bye !!
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)