bug73037.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. --TEST--
  2. Bug #73037 SoapServer reports Bad Request when gzipped, var 0
  3. --EXTENSIONS--
  4. soap
  5. zlib
  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. include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";
  15. function get_data($max)
  16. {
  17. $piece = "<CD>
  18. <TITLE>Empire Burlesque</TITLE>
  19. <ARTIST>Bob Dylan</ARTIST>
  20. <COUNTRY>USA</COUNTRY>
  21. <COMPANY>Columbia</COMPANY>
  22. <PRICE>10.90</PRICE>
  23. <YEAR>1985</YEAR>
  24. </CD>";
  25. $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>';
  26. $end = '</CATALOG></soapenv:Body></soapenv:Envelope>';
  27. $min = strlen($begin) + strlen($piece) + strlen($end);
  28. $max = $max < $min ? $min : $max;
  29. $data = $begin;
  30. $data .= $piece;
  31. while (strlen($data) + strlen($end) < $max) {
  32. /* Randomize a bit, taking gzip in account. */
  33. $tmp = str_replace(
  34. array(
  35. "Empire Burlesque",
  36. "Bob Dylan",
  37. ),
  38. array(
  39. md5(uniqid()),
  40. sha1(uniqid()),
  41. ),
  42. $piece
  43. );
  44. if (strlen($begin) + strlen($tmp) + strlen($end) > $max) {
  45. break;
  46. }
  47. $data .= $tmp;
  48. }
  49. $data .= $end;
  50. return $data;
  51. }
  52. $router = "bug73037_server.php";
  53. $args = substr(PHP_OS, 0, 3) == 'WIN'
  54. ? ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=php_soap.dll"] : [];
  55. $code = <<<'PHP'
  56. $s = new SoapServer(NULL, array('uri' => 'http://here'));
  57. $s->setObject(new stdclass());
  58. $s->handle();
  59. PHP;
  60. php_cli_server_start($code, $router, $args);
  61. 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) {
  62. echo "Iteration $k\n\n";
  63. /* with and without compression */
  64. foreach (array(false, true) as $b) {
  65. $data = get_data($i);
  66. if ($b) {
  67. $data = gzencode($data);
  68. }
  69. $len = strlen($data);
  70. //echo "len=$len\n";
  71. $hdrs = <<<HDRS
  72. POST /bug73037_server.php HTTP/1.1
  73. Content-Type: application/soap+xml; charset=UTF-8
  74. Accept: application/soap+xml, application/dime, multipart/related, text/*
  75. SOAPAction: "urn:adressen#adressen#SetAda"
  76. Expect: 100-continue
  77. Content-Length: ${len}
  78. HDRS;
  79. if ($b) {
  80. $hdrs .="\nContent-Encoding: gzip";
  81. }
  82. //echo "Headers sent:\n$hdrs\n\n";
  83. $fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT, $errno, $errstr, 5);
  84. if (!$fp) {
  85. die("connect failed");
  86. }
  87. if(fwrite($fp, "$hdrs\n\n$data")) {
  88. $out = "";
  89. while (!feof($fp)) {
  90. $out .= fread($fp, 1024);
  91. }
  92. $pos = strpos($out, "<env:Text>");
  93. if (false === $pos) {
  94. echo $out;
  95. goto cleanup;
  96. }
  97. $pos0 = $pos + strlen("<env:Text>");
  98. $pos = strpos($out, "</env:Text>");
  99. if (false === $pos) {
  100. echo $out;
  101. goto cleanup;
  102. }
  103. $len = $pos - $pos0;
  104. echo substr($out, $pos0, $len);
  105. }
  106. cleanup:
  107. fclose($fp);
  108. echo "\n\n";
  109. }
  110. }
  111. ?>
  112. --CLEAN--
  113. <?php
  114. unlink(__DIR__ . DIRECTORY_SEPARATOR . "bug73037_server.php");
  115. ?>
  116. --EXPECT--
  117. Iteration 0
  118. Function 'CATALOG' doesn't exist
  119. Function 'CATALOG' doesn't exist
  120. Iteration 1
  121. Function 'CATALOG' doesn't exist
  122. Function 'CATALOG' doesn't exist
  123. Iteration 2
  124. Function 'CATALOG' doesn't exist
  125. Function 'CATALOG' doesn't exist
  126. Iteration 3
  127. Function 'CATALOG' doesn't exist
  128. Function 'CATALOG' doesn't exist
  129. Iteration 4
  130. Function 'CATALOG' doesn't exist
  131. Function 'CATALOG' doesn't exist
  132. Iteration 5
  133. Function 'CATALOG' doesn't exist
  134. Function 'CATALOG' doesn't exist
  135. Iteration 6
  136. Function 'CATALOG' doesn't exist
  137. Function 'CATALOG' doesn't exist