summaryrefslogtreecommitdiff
path: root/ext/soap/tests/bug73037.phpt
blob: 0a4271f356c11cc430f71b4ae85b660dc5f81055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
--TEST--
Bug #73037 SoapServer reports Bad Request when gzipped, var 0
--CONFLICTS--
server
--SKIPIF--
<?php
	require_once('skipif.inc');
	if (!extension_loaded("zlib")) {
		echo "skip zlib is required for this test";
	}

	if (!file_exists(dirname(__FILE__) . "/../../../sapi/cli/tests/php_cli_server.inc")) {
		echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
	}
?>
--FILE--
<?php

include dirname(__FILE__) . "/../../../sapi/cli/tests/php_cli_server.inc";

function get_data($max)
{
	$piece = "<CD>
		<TITLE>Empire Burlesque</TITLE>
		<ARTIST>Bob Dylan</ARTIST>
		<COUNTRY>USA</COUNTRY>
		<COMPANY>Columbia</COMPANY>
		<PRICE>10.90</PRICE>
		<YEAR>1985</YEAR>
	</CD>";

	$begin = '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><CATALOG>';
	$end = '</CATALOG></soapenv:Body></soapenv:Envelope>';

	$min = strlen($begin) + strlen($piece) + strlen($end);
	$max = $max < $min ? $min : $max;

	$data = $begin;
	$data .= $piece;
	while (strlen($data) + strlen($end) < $max) {
		/* Randomize a bit, taking gzip in account. */
		$tmp = str_replace(
			array(
				"Empire Burlesque",
				"Bob Dylan",
			),
			array(
				md5(uniqid()),
				sha1(uniqid()),
			),
			$piece
		);

		if (strlen($begin) + strlen($tmp) + strlen($end) > $max) {
			break;
		}

		$data .= $tmp;
	}
	$data .= $end;

	return $data;
}

$router = "bug73037_server.php";
$args = substr(PHP_OS, 0, 3) == 'WIN' ? "-d extension_dir=" . ini_get("extension_dir") . " -d extension=php_soap.dll" : "";
$code = <<<'PHP'
$s = new SoapServer(NULL, array('uri' => 'http://here'));
$s->setObject(new stdclass());
$s->handle();
PHP;

php_cli_server_start($code, $router, $args);

foreach (array(1024-1, 1024*8-3, 1024*9+1, 1024*16-1, 1024*32-5, 1024*64+3, 1024*128-7) as $k => $i) {
	echo "Iteration $k\n\n";

	/* with and without compression */
	foreach (array(false, true) as $b) {
		$data = get_data($i);
		if ($b) {
			$data = gzencode($data);
		}
		$len = strlen($data);

		//echo "len=$len\n";

		$hdrs = <<<HDRS
POST /bug73037_server.php HTTP/1.1
Content-Type: application/soap+xml; charset=UTF-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
SOAPAction: "urn:adressen#adressen#SetAda"
Expect: 100-continue
Content-Length: ${len}
HDRS;
		if ($b) {
			$hdrs .="\nContent-Encoding: gzip";
		}
		//echo "Headers sent:\n$hdrs\n\n";
		$fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT, $errno, $errstr, 5);
		if (!$fp) {
		  die("connect failed");
		}

		if(fwrite($fp, "$hdrs\n\n$data")) {
			$out = "";
			while (!feof($fp)) {
				$out .= fread($fp, 1024);
			}

			$pos = strpos($out, "<env:Text>");
			if (false === $pos) {
				echo $out;
				goto cleanup;
			}
			$pos0 = $pos + strlen("<env:Text>");
			$pos = strpos($out, "</env:Text>");
			if (false === $pos) {
				echo $out;
				goto cleanup;
			}
			$len = $pos - $pos0;
			echo substr($out, $pos0, $len);
		}

cleanup:
		fclose($fp);

		echo "\n\n";
		}
}

?>
==DONE==
--CLEAN--
<?php
unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug73037_server.php");
?>
--EXPECT--
Iteration 0

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 1

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 2

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 3

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 4

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 5

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

Iteration 6

Function 'CATALOG' doesn't exist

Function 'CATALOG' doesn't exist

==DONE==