xref: /PHP-7.4/ext/standard/tests/http/bug69337.phpt (revision 94d37a5d)
1--TEST--
2Bug #69337 (Stream context leaks when http request fails)
3--SKIPIF--
4<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22345'); ?>
5--INI--
6allow_url_fopen=1
7--FILE--
8<?php
9require 'server.inc';
10
11function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
12{
13	if($notification_code == STREAM_NOTIFY_REDIRECTED) {
14	  // $http_response_header is now a string, but will be used as an array
15     // by php_stream_url_wrap_http_ex() later on
16       $GLOBALS['http_response_header'] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\0\0\0\0";
17    }
18}
19
20$ctx = stream_context_create();
21stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
22
23$responses = array(
24	"data://text/plain,HTTP/1.0 302 Found\r\nLocation: http://127.0.0.1:22345/try-again\r\n\r\n",
25	"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
26);
27
28$pid = http_server("tcp://127.0.0.1:22345", $responses, $output);
29
30$f = file_get_contents('http://127.0.0.1:22345/', 0, $ctx);
31
32http_server_kill($pid);
33var_dump($f);
34?>
35==DONE==
36--EXPECTF--
37Warning: file_get_contents(http://127.0.0.1:22345/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%ain %s on line %d
38bool(false)
39==DONE==
40