xref: /PHP-7.2/sapi/cgi/tests/011.phpt (revision cbd108ab)
1--TEST--
2header_remove()
3--SKIPIF--
4<?php include "skipif.inc"; ?>
5--FILE--
6<?php
7
8include "include.inc";
9
10$php = get_cgi_path();
11reset_env_vars();
12
13$f = tempnam(sys_get_temp_dir(), 'cgitest');
14
15function test($script) {
16	file_put_contents($GLOBALS['f'], $script);
17	$cmd = escapeshellcmd($GLOBALS['php']);
18	$cmd .= ' -n -dreport_zend_debug=0 -dhtml_errors=0 ' . escapeshellarg($GLOBALS['f']);
19	echo "----------\n";
20	echo rtrim($script) . "\n";
21	echo "----------\n";
22	passthru($cmd);
23}
24
25test('<?php ?>');
26test('<?php header_remove(); ?>');
27test('<?php header_remove("X-Foo"); ?>');
28test('<?php
29header("X-Foo: Bar");
30?>');
31test('<?php
32header("X-Foo: Bar");
33header("X-Bar: Baz");
34header_remove("X-Foo");
35?>');
36test('<?php
37header("X-Foo: Bar");
38header_remove("X-Foo: Bar");
39?>');
40test('<?php
41header("X-Foo: Bar");
42header_remove("X-Foo:");
43?>');
44test('<?php
45header("X-Foo: Bar");
46header_remove();
47?>');
48test('<?php
49header_remove("");
50?>');
51test('<?php
52header_remove(":");
53?>');
54test('<?php
55header("X-Foo: Bar");
56echo "flush\n";
57flush();
58header_remove("X-Foo");
59?>');
60
61@unlink($f);
62?>
63--EXPECTF--
64----------
65<?php ?>
66----------
67X-Powered-By: PHP/%s
68Content-type: text/html; charset=UTF-8
69
70----------
71<?php header_remove(); ?>
72----------
73Content-type: text/html; charset=UTF-8
74
75----------
76<?php header_remove("X-Foo"); ?>
77----------
78X-Powered-By: PHP/%s
79Content-type: text/html; charset=UTF-8
80
81----------
82<?php
83header("X-Foo: Bar");
84?>
85----------
86X-Powered-By: PHP/%s
87X-Foo: Bar
88Content-type: text/html; charset=UTF-8
89
90----------
91<?php
92header("X-Foo: Bar");
93header("X-Bar: Baz");
94header_remove("X-Foo");
95?>
96----------
97X-Powered-By: PHP/%s
98X-Bar: Baz
99Content-type: text/html; charset=UTF-8
100
101----------
102<?php
103header("X-Foo: Bar");
104header_remove("X-Foo: Bar");
105?>
106----------
107X-Powered-By: PHP/%s
108X-Foo: Bar
109Content-type: text/html; charset=UTF-8
110
111
112Warning: Header to delete may not contain colon. in %s on line 3
113----------
114<?php
115header("X-Foo: Bar");
116header_remove("X-Foo:");
117?>
118----------
119X-Powered-By: PHP/%s
120X-Foo: Bar
121Content-type: text/html; charset=UTF-8
122
123
124Warning: Header to delete may not contain colon. in %s on line 3
125----------
126<?php
127header("X-Foo: Bar");
128header_remove();
129?>
130----------
131Content-type: text/html; charset=UTF-8
132
133----------
134<?php
135header_remove("");
136?>
137----------
138X-Powered-By: PHP/%s
139Content-type: text/html; charset=UTF-8
140
141----------
142<?php
143header_remove(":");
144?>
145----------
146X-Powered-By: PHP/%s
147Content-type: text/html; charset=UTF-8
148
149
150Warning: Header to delete may not contain colon. in %s on line 2
151----------
152<?php
153header("X-Foo: Bar");
154echo "flush\n";
155flush();
156header_remove("X-Foo");
157?>
158----------
159X-Powered-By: PHP/%s
160X-Foo: Bar
161Content-type: text/html; charset=UTF-8
162
163flush
164
165Warning: Cannot modify header information - headers already sent by (output started at %s:3) in %s on line 5
166