1--TEST--
2No router, no script
3--SKIPIF--
4<?php
5include "skipif.inc";
6?>
7--FILE--
8<?php
9include "php_cli_server.inc";
10php_cli_server_start(NULL, TRUE);
11
12list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
13$port = intval($port)?:80;
14$output = '';
15
16$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
17if (!$fp) {
18  die("connect failed");
19}
20
21
22if(fwrite($fp, <<<HEADER
23POST / HTTP/1.1
24Host: {$host}
25Content-Type: application/x-www-form-urlencoded
26Content-Length: 3
27
28a=b
29HEADER
30)) {
31	while (!feof($fp)) {
32		$output .= fgets($fp);
33	}
34}
35
36echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n";
37fclose($fp);
38
39
40$output = '';
41$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
42if (!$fp) {
43  die("connect failed");
44}
45
46if(fwrite($fp, <<<HEADER
47GET /main/style.css HTTP/1.1
48Host: {$host}
49
50
51HEADER
52)) {
53	while (!feof($fp)) {
54		$output .= fgets($fp);
55	}
56}
57
58echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n";
59fclose($fp);
60
61$output = '';
62$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
63if (!$fp) {
64  die("connect failed");
65}
66
67if(fwrite($fp, <<<HEADER
68HEAD /main/foo/bar HTTP/1.1
69Host: {$host}
70
71
72HEADER
73)) {
74	while (!feof($fp)) {
75		$output .= fgets($fp);
76	}
77}
78
79echo preg_replace("/<style>(.*?)<\/style>/s", "<style>AAA</style>", $output), "\n";
80fclose($fp);
81?>
82--EXPECTF--
83
84HTTP/1.1 404 Not Found
85Host: %s
86Connection: close
87Content-Type: text/html; charset=UTF-8
88Content-Length: %d
89
90<!doctype html><html><head><title>404 Not Found</title><style>AAA</style>
91</head><body><h1>Not Found</h1><p>The requested resource / was not found on this server.</p></body></html>
92HTTP/1.1 404 Not Found
93Host: %s
94Connection: close
95Content-Type: text/html; charset=UTF-8
96Content-Length: %d
97
98<!doctype html><html><head><title>404 Not Found</title><style>AAA</style>
99</head><body><h1>Not Found</h1><p>The requested resource /main/style.css was not found on this server.</p></body></html>
100HTTP/1.1 404 Not Found
101Host: %s
102Connection: close
103Content-Type: text/html; charset=UTF-8
104Content-Length: %d
105
106<!doctype html><html><head><title>404 Not Found</title><style>AAA</style>
107</head><body><h1>Not Found</h1><p>The requested resource /main/foo/bar was not found on this server.</p></body></html>
108
109