xref: /PHP-8.2/ext/standard/tests/http/bug48929.phpt (revision 95f25837)
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(); ?>
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.1 200 OK\r\n\r\n",
17    );
18
19    ['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
20
21    foreach($responses as $r) {
22
23        $fd = fopen($uri, '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.1
45Host: %s:%d
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.1
54Host: %s:%d
55Connection: close
56Content-Length: 4
57X-Foo: bar
58Content-Type: text/plain
59
60ohai"
61