xref: /PHP-7.2/ext/standard/tests/http/bug61548.phpt (revision 4b1dff6f)
1--TEST--
2Bug #61548 (content-type must appear at the end of headers)
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($header) {
12    $options = [
13        'http' => [
14			'method' => 'POST',
15			'header' => $header,
16            'follow_location' => true,
17        ],
18    ];
19
20    $ctx = stream_context_create($options);
21
22    $responses = [
23		"data://text/plain,HTTP/1.1 201\r\nLocation: /foo\r\n\r\n",
24		"data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
25	];
26    $pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
27
28    $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
29    fseek($output, 0, SEEK_SET);
30    echo stream_get_contents($output);
31
32    http_server_kill($pid);
33}
34
35do_test("First:1\nSecond:2\nContent-type: text/plain");
36do_test("First:1\nSecond:2\nContent-type: text/plain\n");
37do_test("First:1\nSecond:2\nContent-type: text/plain\nThird:");
38do_test("First:1\nContent-type:text/plain\nSecond:2");
39do_test("First:1\nContent-type:text/plain\nSecond:2\n");
40do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:");
41
42?>
43Done
44--EXPECT--
45POST / HTTP/1.0
46Host: 127.0.0.1:12342
47Connection: close
48First:1
49Second:2
50Content-type: text/plain
51
52GET /foo HTTP/1.0
53Host: 127.0.0.1:12342
54Connection: close
55First:1
56Second:2
57
58
59POST / HTTP/1.0
60Host: 127.0.0.1:12342
61Connection: close
62First:1
63Second:2
64Content-type: text/plain
65
66GET /foo HTTP/1.0
67Host: 127.0.0.1:12342
68Connection: close
69First:1
70Second:2
71
72
73POST / HTTP/1.0
74Host: 127.0.0.1:12342
75Connection: close
76First:1
77Second:2
78Content-type: text/plain
79Third:
80
81GET /foo HTTP/1.0
82Host: 127.0.0.1:12342
83Connection: close
84First:1
85Second:2
86Third:
87
88POST / HTTP/1.0
89Host: 127.0.0.1:12342
90Connection: close
91First:1
92Content-type:text/plain
93Second:2
94
95GET /foo HTTP/1.0
96Host: 127.0.0.1:12342
97Connection: close
98First:1
99Second:2
100
101POST / HTTP/1.0
102Host: 127.0.0.1:12342
103Connection: close
104First:1
105Content-type:text/plain
106Second:2
107
108GET /foo HTTP/1.0
109Host: 127.0.0.1:12342
110Connection: close
111First:1
112Second:2
113
114POST / HTTP/1.0
115Host: 127.0.0.1:12342
116Connection: close
117First:1
118Content-type:text/plain
119Second:2
120Third:
121
122GET /foo HTTP/1.0
123Host: 127.0.0.1:12342
124Connection: close
125First:1
126Second:2
127Third:
128
129Done
130