Replaced cli_webserver_workaround client option by a check of CONTENT_TYPE AND HTTP_CONTENT_TYPE entry in SERVER superglobal

This commit is contained in:
Francis Besset 2014-08-14 21:40:13 +02:00
parent fe67cff5ff
commit 15b208d861
11 changed files with 19 additions and 60 deletions

View File

@ -41,15 +41,6 @@ class SoapClient extends \SoapClient
*/
protected $tracingEnabled = false;
/**
* Work around missing header/php://input access in PHP cli webserver by
* setting headers additionally as GET parameters and SOAP request body
* explicitly as POST variable.
*
* @var boolean
*/
private $cliWebserverWorkaround = false;
/**
* cURL instance.
*
@ -108,10 +99,7 @@ class SoapClient extends \SoapClient
if (isset($options['soap_version'])) {
$this->soapVersion = $options['soap_version'];
}
// activate cli webserver workaround
if (isset($options['cli_webserver_workaround'])) {
$this->cliWebserverWorkaround = $options['cli_webserver_workaround'];
}
$this->curl = new Curl($options);
if (isset($options['extra_options'])) {
@ -158,25 +146,6 @@ class SoapClient extends \SoapClient
$location = $soapRequest->getLocation();
$content = $soapRequest->getContent();
/*
* Work around missing header/php://input access in PHP cli webserver by
* setting headers additionally as GET parameters and SOAP request body
* explicitly as POST variable
*/
if ($this->cliWebserverWorkaround === true) {
if (strpos($location, '?') === false) {
$location .= '?';
} else {
$location .= '&';
}
$location .= SoapMessage::CONTENT_TYPE_HEADER.'='.urlencode($soapRequest->getContentType());
$location .= '&';
$location .= SoapMessage::SOAP_ACTION_HEADER.'='.urlencode($soapRequest->getAction());
$content = http_build_query(array('request' => $content));
$headers = array();
}
$headers = $this->filterRequestHeaders($soapRequest, $headers);
@ -189,6 +158,7 @@ class SoapClient extends \SoapClient
$headers,
$options
);
// tracing enabled: store last request header and body
if ($this->tracingEnabled === true) {
$this->lastRequestHeaders = $this->curl->getRequestHeaders();

View File

@ -18,7 +18,6 @@ $options = array(
'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
'connection_timeout' => 1,
);

View File

@ -20,7 +20,6 @@ class MtomServerInteropTest extends TestCase
'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
public function testAttachment()

View File

@ -24,7 +24,6 @@ $options = array(
'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/SwA.wsdl', $options);

View File

@ -23,7 +23,6 @@ class SwaServerInteropTest extends TestCase
'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
public function testUploadDownloadText()

View File

@ -31,7 +31,6 @@ $options = array(
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecuritySigEnc.wsdl', $options);

View File

@ -30,7 +30,6 @@ class WsSecuritySigEncServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
public function testSigEnc()

View File

@ -28,7 +28,6 @@ $options = array(
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
$sc = new BeSimpleSoapClient(__DIR__.'/Fixtures/WsSecurityUserPass.wsdl', $options);

View File

@ -29,7 +29,6 @@ class WsSecurityUserPassServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'cli_webserver_workaround' => true, // Work around missing header access in PHP cli webserver by setting headers additionally as GET parameters.
);
public function testUserPassText()

View File

@ -28,6 +28,13 @@ abstract class SoapMessage
*/
const CONTENT_TYPE_HEADER = 'CONTENT_TYPE';
/**
* $_SERVER key for 'Content-Type' header (with PHP cli-webserver)
*
* @var string
*/
const HTTP_CONTENT_TYPE_HEADER = 'HTTP_CONTENT_TYPE';
/**
* $_SERVER key for 'SOAPAction' header.
*

View File

@ -32,29 +32,19 @@ class SoapRequest extends CommonSoapRequest
*/
public static function create($content, $version)
{
$location = self::getCurrentUrl();
/*
* Work around missing header/php://input access in PHP cli webserver by
* setting headers additionally as GET parameters and SOAP request body
* explicitly as POST variable
*/
if (php_sapi_name() == "cli-server") {
$content = is_null($content) ? $_POST['request'] : $content;
$action = $_GET[SoapMessage::SOAP_ACTION_HEADER];
$contentType = $_GET[SoapMessage::CONTENT_TYPE_HEADER];
} else {
$content = is_null($content) ? file_get_contents("php://input") : $content;
$action = isset($_SERVER[SoapMessage::SOAP_ACTION_HEADER]) ? $_SERVER[SoapMessage::SOAP_ACTION_HEADER] : null;
$contentType = $_SERVER[SoapMessage::CONTENT_TYPE_HEADER];
}
$request = new SoapRequest();
// $content is if unmodified from SoapClient not a php string type!
$request->setContent((string) $content);
$request->setLocation($location);
$request->setAction($action);
$request->setContent((string) (null === $content ? file_get_contents("php://input") : $content));
$request->setLocation(self::getCurrentUrl());
$request->setAction(isset($_SERVER[SoapMessage::SOAP_ACTION_HEADER]) ? $_SERVER[SoapMessage::SOAP_ACTION_HEADER] : null);
$request->setVersion($version);
$request->setContentType($contentType);
if (isset($_SERVER[SoapMessage::CONTENT_TYPE_HEADER])) {
$request->setContentType($_SERVER[SoapMessage::CONTENT_TYPE_HEADER]);
} elseif (isset($_SERVER[SoapMessage::HTTP_CONTENT_TYPE_HEADER])) {
$request->setContentType($_SERVER[SoapMessage::HTTP_CONTENT_TYPE_HEADER]);
}
return $request;
}