xref: /php-src/ext/standard/tests/http/bug79265.phpt (revision f39b5c4c)
1--TEST--
2Bug #79265 (Improper injection of Host header when using fopen for http requests)
3--INI--
4allow_url_fopen=1
5--SKIPIF--
6<?php require 'server.inc'; http_server_skipif(); ?>
7--FILE--
8<?php
9require 'server.inc';
10
11$responses = array(
12    "data://text/plain,HTTP/1.1 200 OK\r\n\r\n",
13);
14
15['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
16
17$opts = array(
18  'http'=>array(
19    'method'=>"GET",
20    'header'=>"RandomHeader: localhost:8080\r\n" .
21              "Cookie: foo=bar\r\n" .
22              "Host: userspecifiedvalue\r\n"
23  )
24);
25$context = stream_context_create($opts);
26$fd = fopen($uri, 'rb', false, $context);
27fseek($output, 0, SEEK_SET);
28echo stream_get_contents($output);
29fclose($fd);
30
31http_server_kill($pid);
32
33?>
34--EXPECT--
35GET / HTTP/1.1
36Connection: close
37RandomHeader: localhost:8080
38Cookie: foo=bar
39Host: userspecifiedvalue
40