Skip to content

Commit

Permalink
Fix parsing multipart/related responses (Bugs #14756, #14854).
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/SOAP/trunk@293174 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Jan Schneider committed Jan 6, 2010
1 parent 93a5206 commit b5bd023
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Base.php
Expand Up @@ -1005,12 +1005,13 @@ function _decodeMimeMessage(&$data, &$headers, &$attachments)
if (isset($structure->body)) {
$data = $structure->body;
$headers = $structure->headers;

unset($headers['']);
return;
} elseif (isset($structure->parts)) {
$data = $structure->parts[0]->body;
$headers = array_merge($structure->headers,
$structure->parts[0]->headers);
unset($headers['']);
if (count($structure->parts) <= 1) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions Transport/HTTP.php
Expand Up @@ -271,7 +271,7 @@ function _parseHeaders($headers)
$this->result_headers = array();
$headers = split("\r?\n", $headers);
foreach ($headers as $value) {
if (strpos($value,':') === false) {
if (strpos($value, ':') === false) {
$this->result_headers[0] = $value;
continue;
}
Expand Down Expand Up @@ -342,13 +342,13 @@ function _parseResponse()
unset($this->result_headers[0]);

switch($code) {
case 100: // Continue
// Continue
case 100:
$this->incoming_payload = $match[2];
return $this->_parseResponse();
case 200:
case 202:
$this->incoming_payload = trim($match[2]);
if (!strlen($this->incoming_payload)) {
if (!strlen(trim($match[2]))) {
/* Valid one-way message response. */
return true;
}
Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -49,6 +49,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="http://www.php.net/license">PHP License</license>
<notes>* Add support for XML Schema include statements.
* Rename QName::ns property to QName::prefix.
* Fix parsing multipart/related responses (Bugs #14756, #14854).
</notes>
<contents>
<dir baseinstalldir="SOAP" name="/">
Expand Down
90 changes: 90 additions & 0 deletions test/bug14756.phpt
@@ -0,0 +1,90 @@
--TEST--
Bug #14756/#14854: Parse multipart/related messages
--FILE--
<?php

require_once 'SOAP/Transport/HTTP.php';

$response = <<<FILE
HTTP/1.1 200
Date: Thu, 09 Oct 2008 15:16:48 GMT
Server: Server
EmbeddedSOAPServer: WASP-C++ Vespa/4.6, build 2162 (Linux i686 2.6.18-8.el5a2xen #1 SMP Tue Apr 3 16:48:05 PDT 2007)
MIME-Version: 1.0
Connection: close
Content-Type: multipart/related; boundary="xxx-WASP-CPP-MIME-Boundary-xxx-yyyyyyyyy-zzzzzzzz-xxx-END-xxx"; type="text/xml"
--xxx-WASP-CPP-MIME-Boundary-xxx-yyyyyyyyy-zzzzzzzz-xxx-END-xxx
Content-Type: text/xml; charset="UTF-8"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SE="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns0:string_Response
xsi:type="xsd:string"
xmlns:ns0="http://systinet.com/xsd/SchemaTypes/"><snip></snip></ns0:string_Response><ns1:doc
href="cid:0xad86d30-0xae618b8-0xae037c0-0xaffa268-0xae62400"
xmlns:ns1="http://systinet.com/xsd/SchemaTypes/"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
--xxx-WASP-CPP-MIME-Boundary-xxx-yyyyyyyyy-zzzzzzzz-xxx-END-xxx
Content-ID: <0xad86d30-0xae618b8-0xae037c0-0xaffa268-0xae62400>
Content-Type: application/binary
<?xml version="1.0"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<snip></snip>
</AmazonEnvelope>
--xxx-WASP-CPP-MIME-Boundary-xxx-yyyyyyyyy-zzzzzzzz-xxx-END-xxx--
FILE;

$sth = new SOAP_Transport_HTTP('http://example.com/');
$sth->incoming_payload = $response;
$result = $sth->_parseResponse();
if ($result) {
echo "OK\n\n";
}
var_dump($sth->headers);
echo "\n" . $sth->response . "\n";
var_dump($sth->attachments);

?>
--EXPECT--
OK

array(6) {
["date"]=>
string(29) "Thu, 09 Oct 2008 15:16:48 GMT"
["server"]=>
string(6) "Server"
["embeddedsoapserver"]=>
string(96) "WASP-C++ Vespa/4.6, build 2162 (Linux i686 2.6.18-8.el5a2xen #1 SMP Tue Apr 3 16:48:05 PDT 2007)"
["mime-version"]=>
string(3) "1.0"
["connection"]=>
string(5) "close"
["content-type"]=>
string(25) "text/xml; charset="UTF-8""
}

<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SE="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns0:string_Response
xsi:type="xsd:string"
xmlns:ns0="http://systinet.com/xsd/SchemaTypes/"><snip></snip></ns0:string_Response><ns1:doc
href="cid:0xad86d30-0xae618b8-0xae037c0-0xaffa268-0xae62400"
xmlns:ns1="http://systinet.com/xsd/SchemaTypes/"/></SOAP-ENV:Body></SOAP-ENV:Envelope>

array(1) {
["cid:0xad86d30-0xae618b8-0xae037c0-0xaffa268-0xae62400"]=>
string(176) "<?xml version="1.0"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<snip></snip>
</AmazonEnvelope>

"
}

0 comments on commit b5bd023

Please sign in to comment.