xref: /PHP-8.0/ext/standard/tests/http/bug61548.phpt (revision 95f25837)
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(); ?>
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' => $pid, 'uri' => $uri] = http_server($responses, $output);
27
28    $fd = fopen($uri, '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--EXPECTF--
45POST / HTTP/1.1
46Host: %s:%d
47Connection: close
48First:1
49Second:2
50Content-type: text/plain
51
52GET /foo HTTP/1.1
53Host: %s:%d
54Connection: close
55First:1
56Second:2
57
58
59POST / HTTP/1.1
60Host: %s:%d
61Connection: close
62First:1
63Second:2
64Content-type: text/plain
65
66GET /foo HTTP/1.1
67Host: %s:%d
68Connection: close
69First:1
70Second:2
71
72
73POST / HTTP/1.1
74Host: %s:%d
75Connection: close
76First:1
77Second:2
78Content-type: text/plain
79Third:
80
81GET /foo HTTP/1.1
82Host: %s:%d
83Connection: close
84First:1
85Second:2
86Third:
87
88POST / HTTP/1.1
89Host: %s:%d
90Connection: close
91First:1
92Content-type:text/plain
93Second:2
94
95GET /foo HTTP/1.1
96Host: %s:%d
97Connection: close
98First:1
99Second:2
100
101POST / HTTP/1.1
102Host: %s:%d
103Connection: close
104First:1
105Content-type:text/plain
106Second:2
107
108GET /foo HTTP/1.1
109Host: %s:%d
110Connection: close
111First:1
112Second:2
113
114POST / HTTP/1.1
115Host: %s:%d
116Connection: close
117First:1
118Content-type:text/plain
119Second:2
120Third:
121
122GET /foo HTTP/1.1
123Host: %s:%d
124Connection: close
125First:1
126Second:2
127Third:
128
129Done
130