xref: /PHP-5.6/ext/standard/tests/http/bug48929.phpt (revision 4b1dff6f)
1--TEST--
2Bug #48929 (duplicate \r\n sent after last header line)
3--INI--
4allow_url_fopen=1
5--SKIPIF--
6<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
7--FILE--
8<?php
9require 'server.inc';
10
11function do_test($context_options) {
12
13	$context = stream_context_create(array('http' => $context_options));
14
15	$responses = array(
16		"data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
17	);
18
19	$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
20
21	foreach($responses as $r) {
22
23		$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
24
25		fseek($output, 0, SEEK_SET);
26		var_dump(stream_get_contents($output));
27		fseek($output, 0, SEEK_SET);
28	}
29
30	http_server_kill($pid);
31}
32
33echo "-- Test: requests with 'header' as array --\n";
34
35do_test(array('header' => array('X-Foo: bar', 'Content-Type: text/plain'), 'method' => 'POST', 'content' => 'ohai'));
36
37echo "-- Test: requests with 'header' as string --\n";
38
39do_test(array('header' => "X-Foo: bar\r\nContent-Type: text/plain", 'method' => 'POST', 'content' => 'ohai'));
40
41?>
42--EXPECTF--
43-- Test: requests with 'header' as array --
44string(%d) "POST / HTTP/1.0
45Host: 127.0.0.1:12342
46Connection: close
47Content-Length: 4
48X-Foo: bar
49Content-Type: text/plain
50
51ohai"
52-- Test: requests with 'header' as string --
53string(%d) "POST / HTTP/1.0
54Host: 127.0.0.1:12342
55Connection: close
56Content-Length: 4
57X-Foo: bar
58Content-Type: text/plain
59
60ohai"
61