xref: /PHP-8.3/ext/soap/tests/bug47021.phpt (revision 8ae4b560)
1--TEST--
2Bug #47021 SoapClient (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked")
3--INI--
4soap.wsdl_cache_enabled=0
5--EXTENSIONS--
6soap
7--SKIPIF--
8<?php
9require __DIR__.'/../../standard/tests/http/server.inc';
10http_server_skipif();
11--FILE--
12<?php
13require __DIR__.'/../../standard/tests/http/server.inc';
14
15function chunk_body($body, $n)
16{
17    $chunks = str_split($body, $n);
18    $chunks[] = '';
19
20    foreach ($chunks as $k => $v) {
21        $chunks[$k] = sprintf("%08x\r\n%s\r\n", strlen($v), $v);
22    }
23
24    return join('', $chunks);
25}
26
27$wsdl = file_get_contents(__DIR__.'/server030.wsdl');
28
29$soap = <<<EOF
30<?xml version="1.0" encoding="UTF-8"?>
31<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
32EOF;
33
34$responses = [
35    "data://text/plain,HTTP/1.1 200 OK\r\n".
36    "Content-Type: text/xml;charset=utf-8\r\n".
37    "Transfer-Encoding: \t  chunked\t \r\n".
38    "Connection: close\r\n".
39    "\r\n".
40    chunk_body($wsdl, 64),
41    "data://text/plain,HTTP/1.1 200 OK\r\n".
42    "Content-Type: text/xml;charset=utf-8\r\n".
43    "Transfer-Encoding: \t  chunked\t \r\n".
44    "Connection: close\r\n".
45    "\r\n".
46    chunk_body($soap, 156),
47];
48
49
50['pid' => $pid, 'uri' => $uri] = http_server($responses);
51
52$options = [
53    'trace' => true,
54    'location' => $uri,
55];
56
57class BugSoapClient extends SoapClient
58{
59    public function __doRequest($request, $location, $action, $version, $one_way = null): ?string
60    {
61        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
62
63        var_dump(strlen($response));
64
65        return $response;
66    }
67}
68
69$client = new BugSoapClient($uri, $options);
70
71var_dump(count($client->getItems()));
72
73http_server_kill($pid);
74
75--EXPECT--
76int(1291)
77int(10)
78