xref: /PHP-8.0/ext/standard/tests/http/bug69337.phpt (revision 95f25837)
1--TEST--
2Bug #69337 (Stream context leaks when http request fails)
3--SKIPIF--
4<?php require 'server.inc'; http_server_skipif(); ?>
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: /try-again\r\n\r\n",
25    "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
26);
27
28['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
29
30$f = file_get_contents($uri, 0, $ctx);
31
32http_server_kill($pid);
33var_dump($f);
34?>
35--EXPECTF--
36Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%ain %s on line %d
37bool(false)
38