1--TEST-- 2Bug #73037 SoapServer reports Bad Request when gzipped, var 0 3--EXTENSIONS-- 4soap 5zlib 6--SKIPIF-- 7<?php 8 if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) { 9 echo "skip sapi/cli/tests/php_cli_server.inc required but not found"; 10 } 11?> 12--FILE-- 13<?php 14 15include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc"; 16 17function get_data($max) 18{ 19 $piece = "<CD> 20 <TITLE>Empire Burlesque</TITLE> 21 <ARTIST>Bob Dylan</ARTIST> 22 <COUNTRY>USA</COUNTRY> 23 <COMPANY>Columbia</COMPANY> 24 <PRICE>10.90</PRICE> 25 <YEAR>1985</YEAR> 26 </CD>"; 27 28 $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>'; 29 $end = '</CATALOG></soapenv:Body></soapenv:Envelope>'; 30 31 $min = strlen($begin) + strlen($piece) + strlen($end); 32 $max = $max < $min ? $min : $max; 33 34 $data = $begin; 35 $data .= $piece; 36 while (strlen($data) + strlen($end) < $max) { 37 /* Randomize a bit, taking gzip in account. */ 38 $tmp = str_replace( 39 array( 40 "Empire Burlesque", 41 "Bob Dylan", 42 ), 43 array( 44 md5(uniqid()), 45 sha1(uniqid()), 46 ), 47 $piece 48 ); 49 50 if (strlen($begin) + strlen($tmp) + strlen($end) > $max) { 51 break; 52 } 53 54 $data .= $tmp; 55 } 56 $data .= $end; 57 58 return $data; 59} 60 61$router = "bug73037_server.php"; 62$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX]; 63if (php_ini_loaded_file()) { 64 // Necessary such that it works from a development directory in which case extension_dir might not be the real extension dir 65 $args[] = "-c"; 66 $args[] = php_ini_loaded_file(); 67} 68$code = <<<'PHP' 69$s = new SoapServer(NULL, array('uri' => 'http://here')); 70$s->setObject(new stdclass()); 71$s->handle(); 72PHP; 73 74php_cli_server_start($code, $router, $args); 75 76foreach (array(1024-1, 1024*8-3, 1024*9+1, 1024*16-1, 1024*32-5, 1024*64+3, 1024*128-7) as $k => $i) { 77 echo "Iteration $k\n\n"; 78 79 /* with and without compression */ 80 foreach (array(false, true) as $b) { 81 $data = get_data($i); 82 if ($b) { 83 $data = gzencode($data); 84 } 85 $len = strlen($data); 86 87 //echo "len=$len\n"; 88 89 $hdrs = <<<HDRS 90POST /bug73037_server.php HTTP/1.1 91Content-Type: application/soap+xml; charset=UTF-8 92Accept: application/soap+xml, application/dime, multipart/related, text/* 93SOAPAction: "urn:adressen#adressen#SetAda" 94Expect: 100-continue 95Content-Length: {$len} 96HDRS; 97 if ($b) { 98 $hdrs .="\nContent-Encoding: gzip"; 99 } 100 //echo "Headers sent:\n$hdrs\n\n"; 101 $fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT, $errno, $errstr, 5); 102 if (!$fp) { 103 die("connect failed"); 104 } 105 106 if(fwrite($fp, "$hdrs\n\n$data")) { 107 $out = ""; 108 while (!feof($fp)) { 109 $out .= fread($fp, 1024); 110 } 111 112 $pos = strpos($out, "<env:Text>"); 113 if (false === $pos) { 114 echo $out; 115 goto cleanup; 116 } 117 $pos0 = $pos + strlen("<env:Text>"); 118 $pos = strpos($out, "</env:Text>"); 119 if (false === $pos) { 120 echo $out; 121 goto cleanup; 122 } 123 $len = $pos - $pos0; 124 echo substr($out, $pos0, $len); 125 } 126 127cleanup: 128 fclose($fp); 129 130 echo "\n\n"; 131 } 132} 133 134?> 135--EXPECT-- 136Iteration 0 137 138Function 'CATALOG' doesn't exist 139 140Function 'CATALOG' doesn't exist 141 142Iteration 1 143 144Function 'CATALOG' doesn't exist 145 146Function 'CATALOG' doesn't exist 147 148Iteration 2 149 150Function 'CATALOG' doesn't exist 151 152Function 'CATALOG' doesn't exist 153 154Iteration 3 155 156Function 'CATALOG' doesn't exist 157 158Function 'CATALOG' doesn't exist 159 160Iteration 4 161 162Function 'CATALOG' doesn't exist 163 164Function 'CATALOG' doesn't exist 165 166Iteration 5 167 168Function 'CATALOG' doesn't exist 169 170Function 'CATALOG' doesn't exist 171 172Iteration 6 173 174Function 'CATALOG' doesn't exist 175 176Function 'CATALOG' doesn't exist 177 178